Problems converting PDF to BMP using ImageMagick?

1.8k views Asked by At

I would like to convert a PDF to BMP. The PDF I am talking about is available here.

I use ImageMagick with the following command :

convert -verbose -resize 256x256 phantom-brain-ellipse.pdf phantom.bmp

But the result is a phantom.bmp file corrupted or empty file with pixel dimensions 0x0.

The error message is :

"/opt/local/bin/gsx" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=/var/tmp/magick-1199-UNts2yPB9u2%d" "-f/var/tmp/magick-1199rG26g03biUuT" "-f/var/tmp/magick-1199-sNgqMmlD53M"
/var/tmp/magick-1199-UNts2yPB9u21 PNG 263x263 263x263+0+0 8-bit sRGB 54.6KB 0.010u 0:00.009
phantom-brain-ellipse.pdf PDF 263x263 263x263+0+0 16-bit sRGB 54.6KB 0.000u 0:00.000
phantom-brain-ellipse.pdf=>phantom.bmp PDF 263x263=>256x256 256x256+0+0 16-bit sRGB 262KB 0.020u 0:00.019

When I convert to PNG everything works fine with the same command :

convert -verbose -resize 256x256 phantom-brain-ellipse.pdf phantom.png

Any idea how to fix that ?

Partial Solution

This command allowed me to get the right BMP :

convert phantom.png BMP3:phantom.bmp

But I don't get why it works !

1

There are 1 answers

7
Kurt Pfeifle On BEST ANSWER

Try:

convert -verbose -resize 256x256 phantom-brain-ellipse.pdf[0] BMP3:phantom.bmp

Update/Explanation

  1. PDF is a multipage format. Potentially, the input PDF has more than one page.

    ImageMagick commands can select a specific page with the naming convention filename[i], where i is the index of the page. Indexing is zero-based, so some.pdf[0] means: "Use page 1 of this PDF."

  2. The SOMEFORMAT:filename convention determines the file format for output files and overrides any file format which may be indicated by the filename suffix. So an output filename of GIF:some.png will create a GIF file with the (wrong) suffix .png.

  3. The BMP3: is a specific version of the general BMP format. By default, BMP:filename or filename.bmp will produce version 4 of BMP. To get version 3 use BMP3:filename.bmp. To get version 2 use BMP2:filename.bmp.

  4. I used BMP3: because you reported that it worked...