ruby-on-railsimagemagickrgbcmykdragonfly-gem

Dragonfly convert not working with ImageMagick's profile option


I am trying to generate an RGB thumbnail for a CMYK pdf file using the Dragonfly gem. It is working fine with this code:

file.image.convert("-flatten -density 300 -quality 100", 'format' => 'jpg', 'frame' => 0).url

The result is the correct url of the thumbnail image.

Since some users upload CMYK documents, I want to convert them using color profiles and the colorspace option:

file.image.convert("-flatten -profile /path_to/USWebCoatedSWOP.icc -profile /path_to/AppleRGB.icc -colorspace rgb -density 300 -quality 100", 'format' => 'jpg', 'frame' => 0).url

The result is always "nil". No error is shown.

When I execute the code (which is shown in the console) manually in the terminal, the file is correctly converted. The "DRAGONFLY: shell command":

convert /path_to/my_cmyk_file.pdf[0] -flatten -profile /path_to/USWebCoatedSWOP.icc -profile /path_to/AppleRGB.icc -colorspace RGB -density 300 -quality 100 /path_to/my_rgb_thumbnail.jpg

The result is this:

/path_to/USWebCoatedSWOP.icc ICC 1x1 1x1+0+0 16-bit sRGB 557168B 0.010u 0:00.000
/path_to/AppleRGB.icc ICC 1x1 1x1+0+0 16-bit sRGB 552B 0.000u 0:00.000
/path_to/my_cmyk_file.pdf[0]=>/path_to/my_rgb_thumbnail.jpg PDF 420x595 420x595+0+0 16-bit sRGB 56625B 0.180u 0:00.190

What could cause the problem within Dragonfly?


Solution

  • I managed to get it to work with a custom processor and the shell_update functionality:

    processor :cmyk_pdf_thumb do |content|
      content.shell_update ext: 'jpg' do |old_path, new_path|
        "convert -density 300 #{old_path}[0] -flatten -profile USWebCoatedSWOP.icc -profile AppleRGB.icc #{new_path}"
      end
    end
    

    Now I can convert CMYK documents by file.image.cmyk_pdf_thumb. Even if I set the ext option to "jpg", I have to encode the result to get a JPEG file:

    file.image.cmyk_pdf_thumb.encode('jpg').url