Color profile problems while converting PDF to JPG

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
pieter

Color profile problems while converting PDF to JPG

Post by pieter »

Hi,

We have problems converting PDF to JPG inside PHP. Converting does work, but on a Linux server the output is a bad quality JPG. This is caused by the PDF (CMYK) input and JPEG (RGB) output. This needs to be translated with color profiles (sRGB and SWOP?). This works OK on our Windows server (good quality there), but it does not work on Linux: it produces the same bad quality output.

We use Ghostscript & IM, installed with the --with-lcms option (before that we got LCMS errors). I searched almost whole Google and forums for this issue, but without results. Has anyone expierience with this issue? Please advise...

Many thanks! Pieter
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Color profile problems while converting PDF to JPG

Post by magick »

For quality conversion of a CMYK PDF to RGB JPEG, make sure you have a modern version of ImageMagick. The current release is 6.3.3-4. Next you have two methods for the colorspace conversion. Try this first:
  • convert -density 300 -colorspace RGB image.pdf image.jpg
Next, ensure you have LCMS support with ImageMagick. Type
  • identify -list configure
Make sure -llcms is associated with the LIBS tag. If so, try this command:
  • convert -density 300 image.pdf +profile '*' -profile USWebCoatedSWOP.icc -profile sRGB.icm image.jpg
pieter

Re: Color profile problems while converting PDF to JPG

Post by pieter »

Thank you for you quick reply! I checked on your comments. Results are getting better, but still not full quality. Can we do better?


1) We use "ImageMagick 6.0.7 03/27/07 Q16". Is this version recent enough?

2) Yes, LCMS support is available:

Code: Select all

[b]identify -list configure[/b]

Path: /usr/lib/ImageMagick-6.0.7/config/configure.mgk

Name          Value
-------------------------------------------------------------------------------
CC            gcc
CFLAGS        -O2 -g -march=i386 -mcpu=i686 -Wall -pthread
CONFIGURE     ./configure --host=i686-redhat-linux-gnu --build=i686-redhat-linux-gnu --target=i386-redhat-linux --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --with-perl --with-x --with-threads --with-magick_plus_plus --with-lcms
COPYRIGHT     Copyright (C) 1999-2004 ImageMagick Studio LLC
CPPFLAGS      -I/usr/include
CVS_BRANCH_TAG HEAD
CXX           g++
CXXFLAGS      -O2 -g -march=i386 -mcpu=i686 -pthread
DISTCHECK_CONFIG_FLAGS --host=i686-redhat-linux-gnu --build=i686-redhat-linux-gnu --target=i386-redhat-linux --program-prefix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/usr/com --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --with-perl --with-x --with-threads --with-magick_plus_plus --with-lcms'CFLAGS=-O2 -g -march=i386 -mcpu=i686'
EXEC-PREFIX   /usr
HOST          i686-redhat-linux-gnu
LDFLAGS       -L/usr/lib -lfreetype -lz
LIB_VERSION   0x607
LIB_VERSION_NUMBER 6,0,7,1
LIBS          -lMagick [b]-llcms[/b] -ltiff -lfreetype -ljpeg -lpng -lbz2 -lz -lpthread -lm -lpthread
NAME          ImageMagick
PREFIX        /usr
QuantumDepth  16
RELEASE_DATE  03/27/07
VERSION       6.0.7
WEBSITE       http://www.imagemagick.org

3) I tried this command:

Code: Select all

convert -density 300 /var/www/vhosts/drukkerijvanbarneveld.nl/httpdocs/test.pdf +profile '*' -profile /var/www/vhosts/drukkerijvanbarneveld.nl/httpdocs/Static/Images/UserUpload/USWebCoatedSWOP.icc -profile /var/www/vhosts/drukkerijvanbarneveld.nl/httpdocs/Static/Images/UserUpload/sRGB.icm /var/www/vhosts/drukkerijvanbarneveld.nl/httpdocs/out/image.jpg
Results are better than before, but unfortunately the output uses still bad coloring:

Original: http://www.drukkerijvanbarneveld.nl/test.pdf
Output: http://www.drukkerijvanbarneveld.nl/out/image.jpg

Please advise...

Many thanks, Pieter
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Color profile problems while converting PDF to JPG

Post by magick »

You will need to define what "bad coloring" means to you. We checked the color conversion and it appears to be working fine-- that is the CMYK colors are correctly being converted to sRGB.
pieter

Re: Color profile problems while converting PDF to JPG

Post by pieter »

Sorry, the quality loss was caused by the JPG compression. After adding -quality 100 to the convert command the quality improved. Thank you for your help!
svirid

Re: Color profile problems while converting PDF to JPG

Post by svirid »

I had the same problem with our conversion tool.
What I did is, I started to call ghostscript instead of the image magic.

here is what solved my problem

gs -q -sDEVICE=jpeg -dSubsetFonts=true -dEmbedAllFonts=true -dUseCIEColor -sOutputFile=$this->destination -r200 -dBATCH -dNOPAUSE $this->sourceFile
Post Reply