1

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.

  • Please give a concrete example of what you start with and what you hope to get as a result. Also, I realise English may not be your native tongue, but what are *"the height of the dimensions"* please? – Mark Setchell Jan 07 '22 at 17:58
  • Updated original post with link to sample image. – Gary C. New Jan 07 '22 at 20:52
  • Any particular reason not to just use **ImageMagick**? https://stackoverflow.com/a/55889365/2836621 – Mark Setchell Jan 07 '22 at 22:07
  • It is being implemented on an embedded device. If possible, I'd prefer to use GraphicsMagick with its smaller footprint. However, it's becoming apparent what GraphicsMagick lacks for the benefit of its reduced size (functionality vs size). – Gary C. New Jan 07 '22 at 22:58
  • What OS/environment is available on the device? `bash`? C++ compiler/cross-compiler? How much functionality do you need - just the cropping or lots of other stuff too? – Mark Setchell Jan 08 '22 at 08:42
  • It's running linux-k2.6 (armv7) with Entware. I can cross-compile packages via a debian live dvd that I have used previously. The only extra functionality that I need is what I've requested in the original post. – Gary C. New Jan 09 '22 at 03:46

1 Answers1

0

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Excellent out-of-the-box thinking to have the shell help with the calculations! I believe your original example may be using bash as I was unable to get it to execute under shell. I've provided a subsequent shell example that works for me. Thank you for your time and assistance, Mark! – Gary C. New Jan 09 '22 at 22:24
  • Yes, the process substitution is a *bash-ism*. Glad you found an alternative that works. Good luck with your project. – Mark Setchell Jan 10 '22 at 07:14