Converting PDF to JPEG is giving negative output

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
HaroldWindt
Posts: 11
Joined: 2015-06-02T05:04:29-07:00
Authentication code: 6789

Converting PDF to JPEG is giving negative output

Post by HaroldWindt »

ImageMagick 6.9.1-0
Ghostscript 9.15
Environment - Linux

We are getting a black background JPEG file when we are trying to conveert PDF to JPEG. Below is the command we are using
convert -alpha off -units pixelsperinch -resize 800X600 Dropbox.pdf[0] -profile "sRGB Color Space Profile.icm" -profile "sRGB Color Space Profile.icm" Dropbox.jpg

File Name - Dropbox.pdf
PDF File Location - https://www.dropbox.com/s/7ehqobvz7lr7g ... x.pdf?dl=0
Output JPEG file - https://www.dropbox.com/s/89i2hv5a6sbwa ... x.jpg?dl=0

The same PDF when we tried converting to JPEG using older version of IM & GS its working fine
ImageMagick 6.5.4-7
Ghostscript 8.70 (2009-07-31)

Can some one help to understanding what is causing the issue with newer version of IM for these specific PDF files
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDF to JPEG is giving negative output

Post by fmw42 »

The following command works for me on IM 6.9.2.0 Q16 Mac OSX and ghostscript 9.10_2. Unix syntax. Note -resize is after the input. Also you only need one profile, since your input image has no profile.

Code: Select all

convert -units pixelsperinch -density 288 Dropbox.pdf[0] \
-alpha off \
-resize 800x600 \
-profile /Users/fred/images/profiles/sRGB.icc \
Dropbox.jpg
check you delegates.xml file for the sDEVICE being used. Mine is


<delegate decode="ps:alpha" stealth="True" command=""gs" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s""/>
HaroldWindt
Posts: 11
Joined: 2015-06-02T05:04:29-07:00
Authentication code: 6789

Re: Converting PDF to JPEG is giving negative output

Post by HaroldWindt »

Tried a simple convert using latest IM & GS and still the output JPEG file is black
convert C:\Users\Admin\Desktop\DropBox.pdf[0] C:\Users\Admin\Desktop\DropBox.jpg

Operating System - Windows 7 (64bit)
ImageMagick Version - 6.9.2
Ghost Script Version - 9.16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting PDF to JPEG is giving negative output

Post by snibgo »

The PDF has a transparent (ie "transparent-black") background. JPG doesn't have transparency, so it removes the transparency, leaving black. If you prefer white:

Code: Select all

convert Dropbox.pdf[0] -background White -flatten x.jpg
snibgo's IM pages: im.snibgo.com
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Converting PDF to JPEG is giving negative output

Post by 246246 »

It seems -alpha remove will generate white background.
(As internal png generated by pngalpha has white background.)

Cite from http://ghostscript.com/doc/current/Devices.htm

Code: Select all

The pngalpha device responds to the following option:
    -dBackgroundColor=16#RRGGBB (RGB color, default white = 16#ffffff)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDF to JPEG is giving negative output

Post by fmw42 »

If the sDEVICE is not pngalpha (for example pnmraw), the alpha off may not give a white background. So snibgo's solution is probably more reliable. But you may need pngalpha for GS to properly read the image, since it has transparency.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Converting PDF to JPEG is giving negative output

Post by 246246 »

Just checking:

$ gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile=- DropBox.pdf | convert - show: # white background

$ gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pnmraw -dFirstPage=1 -dLastPage=1 -sOutputFile=- DropBox.pdf | convert - jpeg:- | display - # white background

$ gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -dFirstPage=1 -dLastPage=1 -sOutputFile=- DropBox.pdf | convert - -alpha remove jpeg:- | display - # white background

$ gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -dBackgroundColor=16#000000 -dFirstPage=1 -dLastPage=1 -sOutputFile=- DropBox.pdf | convert - -alpha remove jpeg:- | display - # black background
HaroldWindt
Posts: 11
Joined: 2015-06-02T05:04:29-07:00
Authentication code: 6789

Re: Converting PDF to JPEG is giving negative output

Post by HaroldWindt »

HaroldWindt wrote:ImageMagick 6.9.1-0
Ghostscript 9.15
Environment - Linux

We are getting a black background JPEG file when we are trying to conveert PDF to JPEG. Below is the command we are using
convert -alpha off -units pixelsperinch -resize 800X600 Dropbox.pdf[0] -profile "sRGB Color Space Profile.icm" -profile "sRGB Color Space Profile.icm" Dropbox.jpg
The same command stated above is giving a good output with the below versions of ImageMagick and GhostScript
ImageMagick 6.8.8-7Q16 x86_64
Ghostscript 9.10

So its working fine with the older version, something broke in the newer version whether its ImageMagick or Ghostscipt
Post Reply