Square thumbnails with ImageMagick (convert)?

This is explained in the official ImageMagick documentation under, “Cut the Thumbnail to Fit”:

An alternative, is rather than pad out the image to fit the specific thumbnail size we want, is to instead cut off the parts of the image that does not fit the final size.

Of course this means you actually lose some parts of the original image, particularly the edges of the image, but the result is a enlarged thumbnail of the center part of the image. This is usually (but not always) the main subject of the image, so it is a practical method of thumbnail creation.

As of IM v6.3.8-3 the special resize option flag '^' was added to make this easier. We just resize using this flag then crop off the parts of the image that overflows the desired size.

And in the context of an example command:

convert -define jpeg:size=200x200 hatching_orig.jpg  -thumbnail 100x100^ \
          -gravity center -extent 100x100  cut_to_fit.gif

Ignacio linked to the correct documentation, however I'll paste it inline here for convenience:

convert -define jpeg:size=200x200 original.jpeg  -thumbnail 100x100^ -gravity center -extent 100x100  thumbnail.jpeg

Similarly, the following is for GraphicsMagick:

gm convert -size 200x200 original.jpeg -thumbnail 100x100^ -gravity center -extent 100x100 +profile "*" thumbnail.jpeg

Explanation:

  • -size 200x200 tells the jpeg decoder we only need this resolution so it can save memory and read the source image faster
  • -thumbnail 100x100^ fast resize making the shortest side 100
  • - gravity center center the next operation
  • -extent 100x100 apply the image to a 100x100 canvas
  • +profile "*" do not save any metainfo to the jpeg (making the resulting image smaller)