I have a few images I want to convert in batch using ImageMagick.
All images should be converted to a specific width, lets say 500px
.
- If an image's width is larger than
500px
, scale it down and preserve the aspect ratio. - If an image's width is less than
500px
, add borders to the sides to make it500px
wide.
The first one is possible using magick mogrify -resize 500x *
, but this also scales images with a smaller width up. How can I prevent that from happening and add borders instead?
I figured I could just add -background black -gravity center
but I don't know how to prevent upscaling.
-resize 500x^>
-extent 500x
too. So my final command wasmagick mogrify -resize '500x^>' -background black -gravity center -extent 500x *
. If you add your comment as an answer I'll accept it!500px
wide, which is not what I want