How do I resize and pad an image to a given size using imagemagick?

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?


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.