23

Say I have a directory of images which is variously 3024×4032 and 4032×3024 pixels, and I want them all resized to 1920×1080.

I want that exact output size, but I don't want the images distorted to fit the size, so I want the edges padded with black as needed to preserve the aspect ratio of the original images. What is the ImageMagick command line to pad the images as needed?

1 Answer 1

28

For each image this command will produce a 1920x1080 version of the image, centered, with the edges padded in black where needed:

convert [input file] -resize 1920x1080 -background black -gravity center -extent 1920x1080 [output file]

Source: ImageMagick documentation for the -extent flag.

4
  • Would you accept you own answer, to be easily found.
    – user.dz
    Commented Nov 5, 2020 at 11:26
  • I think as of some version -extend is no longer a valid option.
    – Andy
    Commented Jun 2, 2022 at 18:08
  • 1
    @Andy It is -extent.
    – Gareth Ma
    Commented Jun 26, 2022 at 0:31
  • Note that the order is important: -gravity center -extent … is not the same as -extent … -gravity center.
    – bfontaine
    Commented Sep 29, 2023 at 14:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .