Page 1 of 1

Resizing and Padding to keep a constant aspect ratio

Posted: 2014-08-31T19:27:42-07:00
by manmath
Hi, I'm badly need help. Here's is the problem at hand.

#1 I've some 2600 pics to upload in the product catalog of a website
#2 The pics are of very high resolutions (> 4000px in height), but their aspect ratio is not same
#3 I want their aspect ratio to be 1:1.5, i.e., 1000x1500 px. I don't want to crop any, but put padding whenever necessary to maintain the said aspect ratio.
#4 If possible also suggest me how recursively resize all the images.

Suggest me through a simple example.

Thanks in advance.

Re: Resizing and Padding to keep a constant aspect ratio

Posted: 2014-08-31T21:39:40-07:00
by fmw42

Code: Select all

convert image -resize 1000x1500 -background somecolor -gravity center -extent 1000x1500 resultimage
If you want to process all the images in a given directory, you can use mogrify

cd to directory containing images

Code: Select all

mogrify -resize 1000x1500 -background somecolor -gravity center -extent 1000x1500 *
But I suggest you create a new directory and use -path in mogrify so that you do not write over your source images. If you want the convert to some new image format, then use -format.

See
http://www.imagemagick.org/Usage/basics/#mogrify

If you have multiple directories, you will need to write a script to loop over each directory and use convert on a list of files in each directory or use mogrify.

Re: Resizing and Padding to keep a constant aspect ratio

Posted: 2014-09-01T00:18:13-07:00
by manmath
Thanks. That worked like a charm. Just one issue is unresolved - how to process images recursively, i.e., the images in the subdirectories.

Re: Resizing and Padding to keep a constant aspect ratio

Posted: 2014-09-01T09:52:06-07:00
by fmw42
manmath wrote:Thanks. That worked like a charm. Just one issue is unresolved - how to process images recursively, i.e., the images in the subdirectories.
You have to write a script (that depends upon your OS) to loop over each subdirectory that you want to process and do mogrify on each.

You have not provided what version of IM you are using nor what OS.

Re: Resizing and Padding to keep a constant aspect ratio

Posted: 2014-09-01T17:41:16-07:00
by manmath
I'm working on ImageMagick-6.7.8.9-10.el7.x86_64 on CEntOS 7.

Re: Resizing and Padding to keep a constant aspect ratio

Posted: 2014-09-01T17:57:54-07:00
by fmw42
manmath wrote:Thanks. That worked like a charm. Just one issue is unresolved - how to process images recursively, i.e., the images in the subdirectories.
What was your exact command line?

Re: Resizing and Padding to keep a constant aspect ratio

Posted: 2014-09-02T01:50:42-07:00
by manmath
mogrify -resize 1000x1500 -background white -gravity center -extent 1000x1500 *