Jason Magee

Developer at Cortex, founder of data.gg and aspiring game dev at Granite Games.


Gamely Digest Follow Up

15 Feb 2015

This is a follow up post to this post in which I promised to post my solution to handling thumbnails when different reviewers submit different aspect ratio images, e.g…

Well, here it is..

for f in *.jpg; do convert "$f" -resize "576x324^" -gravity center -crop 576x324+0+0 +repage "${f%%.jpg}t.jpg"; done

This command does the following things:

  1. Resizes the image as close to 576×324 as possible based on the smallest fitting dimension (indicated by the ^).
  2. Sets the ‘gravity’ to the centre for the next command.
  3. Takes a central crop of the image (central due to previous command) to the size 576×324. The x and y offsets give the location of the top left corner of the cropped image with respect to the original. 0 and 0 in this case.
  4. Repage which removes image data to do with virtual image location. I’ve added this simply because the documentation recommends doing so as a pre-caution when using the crop command.