Color changes when converting PDF to JPG using PHP

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
kjbasiljohn
Posts: 5
Joined: 2015-07-22T15:44:39-07:00
Authentication code: 1151

Color changes when converting PDF to JPG using PHP

Post by kjbasiljohn »

When I am converting PDF to JPG using PHP and Command, the color is changing.
Following command are using

convert -limit memory 0 -limit map 0 -quiet -define pdf:use-cropbox=true -interlace none -density 300x300 +repage "source" "destination"

Original PDF http://basiljohn.com/test/0315+EA+Autumn+4.pdf
Image http://basiljohn.com/test/7664-max.jpg
Image http://basiljohn.com/test/7666-max.jpg

Any help please?
kjbasiljohn
Posts: 5
Joined: 2015-07-22T15:44:39-07:00
Authentication code: 1151

Re: Color changes when converting PDF to JPG using PHP

Post by kjbasiljohn »

ImageMagick version using v6.8.4-10
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color changes when converting PDF to JPG using PHP

Post by fmw42 »

There were changes to IM around 6.8.x that may be affecting your processing. You might upgrade to the current version.

My system will not let me go to the place you have uploaded your images, saying "High Risk Website Blocked". Perhaps you should upload your images to dropbox.com.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Color changes when converting PDF to JPG using PHP

Post by 246246 »

Your input pdf is CMYK. Output is RGB.
Current release of ImageMagick (6.9.1-9) does not change colorspace with your command, i.e. CMYK jpg is generated. So if you want CMYK jpg, upgrade is recommended.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color changes when converting PDF to JPG using PHP

Post by fmw42 »

Your input PDF is CMYK, you probably need to convert it to sRGB with profiles when saving to JPG.

Try this (unix syntax) for the first page. It works for me on IM 6.9.1.9 Q16 Mac OSX

Code: Select all

convert 0315+EA+Autumn+4.pdf[0] \
-profile /Users/fred/images/profiles/USWebCoatedSWOP.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
test_srgb.jpg
use your own path to these profiles.

Please always identify your version of IM and platform. Your version of IM may be too old or buggy to do the convert to CMYK JPG. So you may need an upgrade.

On my Mac OSX with IM 6.9.1.9, a direct conversion looks color inverted when displayed as per the following command line. This is often an issue with CMYK JPG

Code: Select all

convert 0315+EA+Autumn+4.pdf[0] 0315+EA+Autumn+4_0.jpg
So I would stick with the profile conversion to sRGB as the safest measure. Some viewers do not handle CMYK JPEG very well.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color changes when converting PDF to JPG using PHP

Post by fmw42 »

This may also work, but the profile method gives more accurate colors.

Code: Select all

convert -colorspace sRGB 0315+EA+Autumn+4.pdf[0] test_srgb2.jpg
kjbasiljohn
Posts: 5
Joined: 2015-07-22T15:44:39-07:00
Authentication code: 1151

Re: Color changes when converting PDF to JPG using PHP

Post by kjbasiljohn »

Thank you so much, its much better now. I have used following command.

convert -limit memory 0 -limit map 0 -quiet -define pdf:use-cropbox=true -interlace none -background white -alpha remove -density 300x300 +repage -colorspace sRGB " SOURCE -quality 95 jpg:" DESTINATION;

can you please tell me from where i can download, sRGB.icc

Thank You
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color changes when converting PDF to JPG using PHP

Post by snibgo »

Look in the directory that contains your convert program.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color changes when converting PDF to JPG using PHP

Post by fmw42 »

snibgo wrote:Look in the directory that contains your convert program.
I do not think they are there by default. I think they must be installed. At least that is how it is on my Mac. Neither the IM download folder nor my folder that contains the installed convert program have profiles located there.

I installed them from:

Get them from profiles.zip at http://www.imagemagick.org/download/delegates/
or
http://www.mattbeals.com/icc/

or for just sRGB.icc, you can get it at http://www.color.org/srgbprofiles.xalter
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Color changes when converting PDF to JPG using PHP

Post by snibgo »

Thanks for the correction. sRGB.icc is provided with the IM installation on Windows, but may not be with other installations.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Color changes when converting PDF to JPG using PHP

Post by fmw42 »

snibgo wrote:Thanks for the correction. sRGB.icc is provided with the IM installation on Windows, but may not be with other installations.
Perhaps that is the case with all binaries, but not when installing from source?
kjbasiljohn
Posts: 5
Joined: 2015-07-22T15:44:39-07:00
Authentication code: 1151

Re: Color changes when converting PDF to JPG using PHP

Post by kjbasiljohn »

Thank you so much guys for all the help. I didn't try with profiles yet. I will let you know once after I have used that.
Post Reply