I have a bunch of images and trying to convert them to pdf using the below command:

$ convert *.jpg -resize 1240x1753 \ 
                      -extent 1240x1753 -gravity center -background white \
                      -units PixelsPerInch -density 150x150 multipage.pdf

It makes a pdf of A4 size. But the images are not centered. They are movied to NorthWest side. How to ensure the images are centered (both side ways and up and down)

1 Answer 1


Put -gravity center before the -extend option:

convert *.jpg -resize 1240x1753 -background white \
    -gravity center -extent 1240x1753 \
    -units PixelsPerInch -density 150x150 multipage.pdf
  • Any explanation of why the order of the options would be helpful & appreciated.
    – gatorback
    Commented Feb 12, 2021 at 14:04
  • You need to center the image before you set the its size with -extend or it won't have an effect.
    – Freddy
    Commented Feb 12, 2021 at 14:43
  • Thanks for the explanation. Perhaps I am having the same problem. I invite you to review: unix.stackexchange.com/q/634115/182280
    – gatorback
    Commented Feb 12, 2021 at 14:49

You must log in to answer this question.

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