Page 1 of 1

White areas in PDF turns black in JPG output

Posted: 2012-01-11T03:45:31-07:00
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

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T11:02:56-07:00
by fmw42
put the -scale after your input image in the command line

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T11:30:37-07:00
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!

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T11:45:46-07:00
by fmw42
Can you post a link to one of the troubling pdf files so others can test with it?

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T12:09:36-07:00
by glennrp
Try with the "-background white" option.

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T14:26:17-07:00
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!

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T15:38:53-07:00
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

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T15:48:17-07:00
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!

Re: White areas in PDF turns black in JPG output

Posted: 2012-01-11T15:50:36-07:00
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

Re: White areas in PDF turns black in JPG output

Posted: 2017-12-28T04:17:37-07:00
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!