11

I'm unable to center a converted *.png file with ImageMagick's gravity option. Gravity seems to have no effect in the following command. On the contrary it erases everything and the output becomes white page.

convert puma1.png -compress jpeg \
                  -resize 1755x2475 \
                  -units PixelsPerInch \
                  -density 150x150 \
                  -page A3 \
                  -gravity center puma1.pdf

ImageMagick version is 6.8.6-9 2014-03-06 Q16.

Braiam
  • 35,991
mabalenk
  • 531
  • Can you post the puma1.png file please? BTW that command doesn't work for me either. – slm Jul 04 '14 at 16:14
  • Closely related: "How to mount a .jpg centered into a .pdf (using defined page size and borders)?" http://unix.stackexchange.com/q/43946 – tanius Aug 04 '15 at 11:35

1 Answers1

17

Try using extent instead like this:

$ convert puma1.png -gravity center \
    -background white \
    -compress jpeg \
    -extent 1755x2475 puma1.pdf

Example

Your gravatar.

        ss #1

And the resulting PDF file.

$ convert 453f11e81477e1e0334962ee262b3bcd.png -gravity center \
    -background white \
    -extent 500x500 \
    -compress jpeg 453f11e81477e1e0334962ee262b3bcd.pdf

ss #2

References

slm
  • 369,824
  • That... looks UGLY! – Braiam Jul 04 '14 at 17:19
  • That's the switches. – slm Jul 04 '14 at 18:15
  • 1
    Thank you. That solved my problem. The original command with the new options is: convert puma1.png -gravity center -background white -compress jpeg -resize 1755x2475 -extent 1755x2475 -units PixelsPerInch -density 150x150 puma1.pdf It seems the option -page A3 kills the output. In case I use it, I still get the blanc page at an output. What about -resize and -extent. Are they mutually exclusive? – mabalenk Jul 04 '14 at 20:19