After several times needing a command to split an image into two pieces, one of which having a fixed size (e.g. 32 px), I decided to enhance the split
command with a new native syntax.
Previously, it was possible to split an image into fixed-size blocks along an axis, for instance, for 32px blocks:
$ gmic sample colorful,128 split x,-32
But in this case, if the image width is larger than 64
, then you end up with more than 2 blocks. In the example above, you actually get 4 images:
And if you want only to split your images in two parts, then you have to re-append the last images together in a second step, like:
$ gmic sample colorful,128 split x,-32 a[^0] x
But honestly, that’s a bit a shame to have to “fix” what the previous command did too much.
Another solution would be to use the crop
command:
$ gmic sample colorful,128 +crop 32,100% crop.. 0,31
But it’s a bit tedious to write.
Now, in G’MIC 3.6.0_pre, you can force the command split
to split an image while specifying the max number of parts you want, as an additional argument (here, max_parts=2
);
$ gmic sample colorful,128 split x,-32,2
Another useful addition is that you can also specify the size of the split as a percentage of the image dimension, like:
$ gmic sample colorful,128 split x,-33.333%,2
The example above will split the image in 2 parts : one representing 1/3 of the image width, the other, 2/3:
There you go, nothing too amazing, but I’m sure it will come in handy some day