Renee
Renee

Reputation: 21

Batch Resize Photos While Maintaining the Aspect Ratio AND Fitting to a specific pixel size

I am looking to batch resize pictures to a specific pixel size while maintaining the aspect ratio. Is their a way that the picture aspect can be preserved and the rest of the space can be filled in with white? For example, I resize an image to 200 x 200 and due to preserving the aspect ratio it is changed to 200 x 194. I would like the actual image to remain 200 x 194 and white space to fill in the remaining area to create an image that is 200 x 200 px. Thank you in advance!

Upvotes: 2

Views: 738

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207465

You can do that with ImageMagick which is included in most Linux distros and is available for macOS and Windows.

Just in Terminal, or Command Prompt on Windows:

magick input.jpg -background white -resize 200x200 -gravity center -extent 200x200 result.jpg

If you have many files to do, you may be better using ImageMagick's mogrify command, which will do them all in one go for you! So make a new directory called processed for the output files and then use this to process all PNG files in the current directory:

magick mogrify -path processed -background white -resize 200x200 -gravity center -extent 200x200 '*.png' 

I don't know if you are on Windows or not, so you may or may not need the single quotes around the filenames at the end of that command. Basically, it determines whether the expansion of the filename list is done by the shell (which has limitations on the number of files), or internally by ImageMagick (which does not).


If you are running anything older than v7, the commands become:

convert input.jpg ...

or

mogrify ...

Upvotes: 2

Related Questions