Page 1 of 1

How to center pictures on colored background?

Posted: 2015-02-01T10:04:34-07:00
by FastBill
I have some photos of different sizes which I need to resize to fit within a rectangle of 576px X 432px while preserving their aspect ratios. I then need to center each photo on a blue background of exactly 720px X 540px. Most original photos are larger than 720x540, a few are smaller. I've used mogrify to resize the original photos into another folder:

mogrify -format bmp -path ..\name-of-target-folder -resize 576x432 *.*

How do I then center each of these resized images on a new image of 720x540, surrounding the photos with a blue background (#2f3699)?

Can this be done with a single IM command? (If so, how?) If not, what command(s) should I perform after this mogrify?

Thanks,
FastBill

Re: How to center pictures on colored background?

Posted: 2015-02-01T10:12:07-07:00
by snibgo
Sorry, I don't know mogrify. With convert, you could "-background #2f3699 -gravity center -entent 720x540". This might also work in mogrify.

See http://www.imagemagick.org/script/comma ... php#extent

Re: How to center pictures on colored background?

Posted: 2015-02-01T12:44:20-07:00
by FastBill
Thanks...For testing, I have 4 JPG photos. Each photo is larger than 576 x 432. I tried this command:

Code: Select all

convert  0*.jpg  -background #2f3699 -gravity center -extent 720x540 Slide%d.png
The result was that each photo was resized to 720 x 540, completely filling that space with no blue background. Not what I was hoping for.

Next, I tried this sequence of commands:

Code: Select all

mogrify -format bmp -path ..\TEST_OUT -resize 576x432 *.*
convert  0*.bmp  -background #2f3699 -gravity center -extent 720x540 Slide%d.png
The mogrify command converted each of the photos to a BMP, resizing each one to fit within a 576x432 rectangle. It maintained the aspect ratio of each photo. Then, applying the convert command to these resized images centered each of them in a 720x540 blue rectangle.

Success! Thanks for your help.

Re: How to center pictures on colored background?

Posted: 2015-02-01T13:16:54-07:00
by snibgo
Yes, each image needs to be resized before the extent. You might find you can do resize and extent in a single mogrify. I don't know.