White areas in PDF turns black in JPG 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
patrikcar
Posts: 6
Joined: 2011-10-20T01:24:51-07:00
Authentication code: 8675308

White areas in PDF turns black in JPG output

Post by patrikcar »

Hello there,

I have quite strange problem, as I see it.

My input file is a PDF and I'm creating two different jpg files from the PDF, one thumbnail and one preview.
On some PDF files white areas are turning black, especially white backgrounds. The strange thing is that it only happens when I add a -scale command in command line.
If I exclude the -scale command, the file looks perfect.

Using ImageMagick 6.7.4-2 Q16 dll
GhostScript 9.04
Windows 2008 R2 Server 64-bit

For thumbnails I use this command:
-convert -colorspace sRGB -scale 100x100 my_input_file.pdf my_output_file.jpg

For previews I use this command
-convert -colorspace sRGB my_input_file.pdf my_output_file.jpg

The only thing that differs is the -scale command, I've tried using different ways to specify the size, with no luck.
Any ideas of what I'm doing wrong?

Best regards,

Patrik Berzander
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White areas in PDF turns black in JPG output

Post by fmw42 »

put the -scale after your input image in the command line
patrikcar
Posts: 6
Joined: 2011-10-20T01:24:51-07:00
Authentication code: 8675308

Re: White areas in PDF turns black in JPG output

Post by patrikcar »

Thanks for your answer, unfortunately that doesn't make a difference at all.
Same output even if I use:
-convert -colorspace sRGB my_input_file.pdf -scale 100x100 my_input_file.pdf my_output_file.jpg

I've also tried
convert my_input_file.pdf -colorspace sRGB -scale 100x100 my_output_file.jpg
and
convert my_input_file.pdf -scale 100x100 my_output_file.jpg

All these gives me the same incorrect output.
I appreciate any help I can get!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White areas in PDF turns black in JPG output

Post by fmw42 »

Can you post a link to one of the troubling pdf files so others can test with it?
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: White areas in PDF turns black in JPG output

Post by glennrp »

Try with the "-background white" option.
patrikcar
Posts: 6
Joined: 2011-10-20T01:24:51-07:00
Authentication code: 8675308

Re: White areas in PDF turns black in JPG output

Post by patrikcar »

I just tried -background white as well, however with the same incorrect result.

If anyone would like to give it a try, here are links to all files.
Original PDF file:
http://212.181.38.117:8080/im/String.pdf

The following command "convert -colorspace sRGB String.pdf Preview.jpg" created this file:
http://212.181.38.117:8080/im/Preview.jpg

The following command "convert -colorspace sRGB String.pdf -scale 100x100 Thumbnail.jpg" created this file:
http://212.181.38.117:8080/im/Thumbnail.jpg

Thanks again for looking into this, much appreciated!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White areas in PDF turns black in JPG output

Post by fmw42 »

your image has transparency and jpg does not support transparency, so you have to flatten it against a white background (or save to gif or png or tiff)

try this, it works for me

convert -colorspace sRGB string.pdf -scale 100x100 -background white -flatten string.jpg
patrikcar
Posts: 6
Joined: 2011-10-20T01:24:51-07:00
Authentication code: 8675308

Re: White areas in PDF turns black in JPG output

Post by patrikcar »

Thank you so much, now it works like a charm!
Seems to work fine without the -background white command as well.

Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: White areas in PDF turns black in JPG output

Post by fmw42 »

patrikcar wrote:Thank you so much, now it works like a charm!
Seems to work fine without the -background white command as well.

Thanks again!
The default -background is white.

see
http://www.imagemagick.org/Usage/layers/#flatten
http://www.imagemagick.org/script/comma ... background
desh@
Posts: 1
Joined: 2017-12-28T04:15:04-07:00
Authentication code: 1152

Re: White areas in PDF turns black in JPG output

Post by desh@ »

fmw42 wrote: 2012-01-11T15:38:53-07:00 your image has transparency and jpg does not support transparency, so you have to flatten it against a white background (or save to gif or png or tiff)

try this, it works for me

convert -colorspace sRGB string.pdf -scale 100x100 -background white -flatten string.jpg
Wonderful! thanks a lot!
Post Reply