Manipulate Images with ImageMagick

Instead, you can glean image size with the identify command, as shown here:


manga.gif GIF 358x313 358x313+0+0 8-bit sRGB 256c 88.5KB
 ↪0.000u 0:00.000
manga.jpg JPEG 358x313 358x313+0+0 8-bit sRGB 85.4KB 0.000u
 ↪0:00.000
manga.png PNG 358x313 358x313+0+0 8-bit sRGB 266KB 0.000u
 ↪0:00.000

That's better. It's consistently the third parameter, which means that a simple script can strip out everything but the image dimensions:


$ for image in manga*; do   identify $image | cut -f1,3 -d\  ; done
manga.gif 358x313
manga.jpg 358x313
manga.png 358x313

Easy enough, and notice that the cut command is invoked both with a space as the default field delimiter and specifying that you want field 1 and 3 but none of the others.

And Next Time...

Okay, ImageMagick is complicated. In fact, I didn't really get much into scripting here, but in my next article, I'll explain how to turn all this knowledge of convert, mogrify and identify into some pretty sick scripts. See you then!

______________________

Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.