Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Generating thumbnails of PDFs with imagemagick sometimes renders incorrect colors. We're using an old version of imagemagick (6.5.7-8, that's the version installed on the heroku servers). Here is the command we're currently using:

convert \
  -size "725x1200>" \
  -colorspace RGB \
  -flatten \
  -density 300 \
  -quality 100 \
   input.pdf \
   output.jpg

I've tried using different colorspaces like sRGB,YIQ,.. but none of them are rendering the color correctly.

Using imagemagick-6.7.7-6 locally works so I've tried to bundle the 'convert' command within my application /bin directory, the command works but the result is still wrong, so it seems that the problem comes either from another imagemagick command used by 'convert' or from another library.

Here's an example of the outputs:

  • Correct output: on the left
  • Wrong output: on the right

Strangely, with some pages of the same pdf the output is always correct. Any idea which library or command could be the issue, or if there is a proper set of options to pass to imagemagick to always get it right?

Thanks in advance for your help.

share|improve this question
    
Looks almost like it's not so much that the color is wrong... as it looks like it is converting a 16- or 32 bit image palette to a 256 color palette... at least from that example you gave. Not only was the teal changed to a bright green, but the blurry text was sharpened quite a bit (not legible, but as if there were fewer shades of grey). The times it appears to work could be due to the specific colors themselves, or the lack of distinct colors? –  Bon Gart Jul 5 '12 at 15:48
    
Thanks for the pointer Bon, I actually tried to set -colors 32 but without success. From the assumption that imagemagick is using ghostscript I then went on trying to see the output directly from it gs -dNOPAUSE -sDEVICE=jpeg -r144 -sOutputFile=out.jpg in.pdf to identify the colorspace. The output was already wrong! Passing -dUseCIEColor fixes it. But how can I tell imagemagick to pass this option along to gs? –  Bastien Jul 5 '12 at 16:56
    
@kurt-pfeifle thanks for adding the pictures in there, I didn't have enough reputation points to do it myself –  Bastien Jul 6 '12 at 22:33

1 Answer 1

up vote 2 down vote accepted

After some more investigation, it appears that the problem comes from ghostscript which is missing the -dUseCIEColor option. And from what I've gathered around the web it is not possible to pass parameters to ghostscript through imagemagick. What is possible though is to call the 2 commands together with a pipe: http://stackoverflow.com/questions/653380/converting-a-pdf-to-png

My specific use case

This is a bit more specific to my use case, but I thought someone might be interested. As we're generating thumbnails via Paperclip in our rails application, I created a new paperclip processor to take care of the pdf to jpg conversion and then imagemagick takes over to do the usual resizing. My code with an example here: https://gist.github.com/3059321

share|improve this answer
    
Why do you need to post-process the JPEGs with imagemagick at all? Can't you add all the params to Ghostscript so you get the sizes you want ? –  Kurt Pfeifle Jul 6 '12 at 18:26
    
'...possible to call the 2 commands together with a pipe...' -- But you didn't upvote this answer, eh? :-) –  Kurt Pfeifle Jul 6 '12 at 18:28
    
Good point, upvoted now ;) About only using ghostscript, I suppose I could, as I said, in my specific case Paperclip is automatically doing it for me, but there might be a way to only run the ghostscript processor. –  Bastien Jul 6 '12 at 22:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.