imagemagickcroptilesgraphicsmagick

How to crop to equally sized tiles using GraphicsMagick?


Is it possible to crop equally sized tiles using GraphicsMagick, similar to ImageMagick's crop "@" modifier?

convert montage.gif -crop 5x1@ +repage +adjoin montage_%d.gif

Is it possible to use GraphicsMagick's crop "%" modifier, if the height of the image dimensions are constant?

Sample image directly from the ImageMagick manual:

https://legacy.imagemagick.org/Usage/crop/montage.gif

I would like to divide the sample image into 5 equal tiles, as shown in the ImageMagick manual.


Solution

  • You can maybe let bash do the work for you instead:

    # Get height and width of image
    read h w < <(gm identify -format "%h %w" montage.gif)  
    
    # Crop into 5 full-height, equal width parts
    gm convert montage.gif -crop $((w/5))x$h +adjoin result%d.jpg
    

    You can maybe let shell do the work for you instead:

    gm convert montage.gif -trim -gravity center trimmed.gif;
    
    d=$(gm identify -format "%h %w" trimmed.gif); h=$(echo $d | grep -ioE "([0-9]+\s)"); w=$(echo $d | grep -ioE "(\s[0-9]+)"); echo $h; echo $w;
    
    gm convert trimmed.gif -gravity center -crop $((w/5))x$h +adjoin result%d.jpg