1

I have some arbitrarily-sized images for which I want to produce fixed-size 800x600 thumbnails, which keep the original image ratio and add white letterboxing to make up the rest of the space. I'd like the letterboxing to be as minimal as possible, which means that the process would do the following:

  • choose whichever axis is largest
  • if x is largest, scale the image (keeping the ratio) so that new x is 800.
  • if y is largest, scale the image (keeping the ratio) so that new y is 600.
  • the result, at this point, will not be 800x600 (unless the original happened to be exactly 4:3 ratio), so centre the result in an 800x600 rectangle and add a white background.

I can do the first 3 steps with convert -resize 800x600 $input $output so I suppose I could overlay that on top of another image using some other imagemagick tool, but it would be great if I could do it in one hit. Anyone know if this is possible?

2

I actually just figured it out: it does require an 800x600 white image to merge with, but that's fine.

convert ~/white.jpg ~/input.png  -resize 800x600 -gravity center -composite ~/output.jpg

If there's a general opinion that posting a question and then answering it myself is a waste of time, then i'm happy to delete the question.

  • I was waiting to see if someone had a solution which didn't require an existing blank white image to merge with (which would seem cleaner), but since none have appeared i'll mark mine as correct, thanks. – Max Williams Mar 7 '16 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.