How to batch resize to a specific aspect ratio by adding white borders

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
feelart
Posts: 16
Joined: 2013-07-09T08:08:24-07:00
Authentication code: 6789

How to batch resize to a specific aspect ratio by adding white borders

Post by feelart »

Hello,

I have a bunch of (scan) jpegs, which have different pixel resolutions and display ratios.
for instance 730x1080, 764x1080, 2059x2912

I which to convert all of them to A4 format, aka 210x297 in whatever sufficient dpi.
It means that some jpeg, do need some white borders on their width, or on their top&bottom borders, in order to output in A4 format.

Border(http://www.imagemagick.org/Usage/crop/#border) could do it if I indivually count for every scan, but here in a batch process I do not know which input ratio I have for each image.

Additionnaly, I wish to resize the longest side to a specific pixel size, say 1200, so that all output have same dpi.

How can I do that?

Thanks

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to batch resize to a specific aspect ratio by adding white borders

Post by anthony »

LOok at the examples in Thumbnails, Padding Images
http://www.imagemagick.org/Usage/thumbnails/#pad

However if you are not after a specific size just a specific ratio. That can be trickier.
See 'Squaring an image' whcih is very simular to what you are after.
http://www.imagemagick.org/Usage/thumbnails/#square
You just need to adjust the 'math' to set the width to height ratios. ;-)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to batch resize to a specific aspect ratio by adding white borders

Post by anthony »

Additional...
This is also related.. Rotate with internal crop Preserving Aspect Ratio
http://www.imagemagick.org/Usage/distor ... te_methods
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked