linux - JPG files are too small when converted from PDF with imagemagick

07
2013-09
  • Trude

    I'm on Ubuntu 10.04 with imagemagick. I used this command:

    convert myfile.pdf -density 300 file.jpg
    

    This works well, but the JPGs are only about an inch high. How can I preserve the paper size in the conversion process?

  • Answers
  • scratchresistor

    You can set the -density before you read the source pdf, so you can do

    convert -density 300 myfile.pdf myfile.jpg
    

    and it'll read the pdf at 300dpi, then render out the jpg at the original size of the pdf, whatever that was.

  • N.N.

    I don't know if Imagemagick can sense the correct height automatically. However if you can come up with the correct height in pixel you can set the height manually.

    According to http://www.indigorose.com/forums/archive/index.php/t-13334.html an A4 paper has the height of 3508 pixels in 300 dpi so then you can do

    convert myfile.pdf -density 300 -geometry x3508 file2.jpg
    

    This command sets the width to 3508 pixels and preserves aspect radio. See http://www.imagemagick.org/script/command-line-processing.php#geometry for details on the -geometry argument.


  • Related Question

    osx - Imagemagick, Snow Leopard and PDF Conversion
  • Peer Allan

    Having difficulties with Imagemagick and Snow Leopard.

    Imagemagick was installed using the install script from here here. Everything builds and installs correctly. Imagemagick behave normally for all commands (that I can find) except when trying to convert a PDF. For example,

    $ convert my.pdf my.jpg
    Segmetation Fault
    

    I thought it may be ghostscript and tried to run the command that Imagegick delegates too (via the -verbose option)

    $ convert -verbose spec/fixtures/documents/upload_test_file.pdf test.jpg
    "gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=/var/folders/Xz/Xz6TDr0DFQaV5J1F7Ndamk+++TM/-Tmp-/magick-4zvJXfSz" "-f/var/folders/Xz/Xz6TDr0DFQaV5J1F7Ndamk+++TM/-Tmp-/magick-O7a9fDyp" "-f/var/folders/Xz/Xz6TDr0DFQaV5J1F7Ndamk+++TM/-Tmp-/magick-rBEzLUsx"
    Segmentation fault
    $ "gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=my.jpg" "-fmy.pdf"
    

    And it works. It creates the pnmrow file as its supposed to.

    I am not sure where to go from here, anyone else seen this or seen it and solved it?

    EDIT:

    As Kasper Souren answered below, I have since switched to Homebrew to manage these libraries.


  • Related Answers
  • Devon

    Looks like the imagemagick team is aware of the problem and it was fixed in version 6.5.5-8.

    The MacPorts package uses the newer version of ImageMagick as of 9/16/09. Try doing a self update and then upgrading php5-imagick.

    sudo port selfupdate
    sudo port upgrade php5-imagick
    

    This fixed the problem for me.

  • Lara Dougan

    A segmentation fault is an error with the memory handling in the program, so it would be either a bug in the build processes or in the program itself. I installed ImageMagick using MacPorts rather than building from the source on their side and the MacPorts version of ImageMagick also seems to be bugged because of ghostscript. If you open the file in Preview, the Save As... JPEG should work fine.

    EDIT:

    I messed around with this some more and have something that works using ghostscript:

    gs -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT \
      -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 \
      "-sDEVICE=jpeg" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 \
      "-r72x72" "-sOutputFile=out.jpeg" in.pdf

    Where out.jpeg is the output file and in.pdf at the end is your input file.

    You can also change -r72x72 to some other resolution if you want to tweak the output resolution higher than 72 dpi.

  • Kasper Souren

    I suggest moving to Homebrew, a more modern variant of macports and fink.

    brew install imagemagick