ImageMagick command line snippets

Created: 2021-01-28. Last updated: 2021-01-28. index

My Linux distro didn't have a magick command when ImageMagick was installed, therefore I use the convert, composite and compare commands instead, which should be equivalent to magick convert etc.


Resize a JPEG image, reduce its quality, and strip EXIF tags

convert input.jpg -resize 640x480 -filter box -quality 50 abcd.jpg

The option -filter box applies binning: an input area of, say, 4×4 pixels is averaged into a single output pixel, technically increasing the signal-to-noise ratio of the image. (Whether it's actually useful, I don't know.) See this list of resolutions divisible by 16 to keep the image size macroblock-aligned.


Compare two images

For example, to visualize the effects of lossy compression or re-compression.

compare original.jpg after.jpg comparison.png

This highlights changed pixels in red. I don't really like this; I wanted more of an image-Aimage-B effect. The following does this:

composite first.png second.jpg -compose difference out.png

There's also -compose difference, which subtracts the darker color from the lighter; minus just subtracts the first from the second.