Pad image to fit a given aspect ratio

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?".
mki

Re: Pad image to fit a given aspect ratio

Post by mki »

Good question.
I'm not really sure what would be the most consistent behaviour.
Maybe copying, but on the other hand this also might be an unnecessary overhead.
What do you think?

btw: Is it safe to give the same input and output filename to your script? (The input file will be overwritten by the output, of course.)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pad image to fit a given aspect ratio

Post by fmw42 »

As far a I know you can have the input and output have the same name. The latter just overwrites the former whether there is a change or not. At least that is the way it works in IM on my Mac. Of course that is somewhat dangerous as if you make a mistake, then you lose your input image (unless you have a backup).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Pad image to fit a given aspect ratio

Post by fmw42 »

I have updated the script now to include a tolerance relative to the absolute diff between the desired aspect ratio and the image aspect ratio. If the diff is less than or equal to the tolerance value, then no padding will take place. The input will simply be copied to the output. The default is 0 (always pad). Values are floats>=0.
mki

Re: Pad image to fit a given aspect ratio

Post by mki »

This updated version is perfect.

Thank you so much!
Post Reply