Question

I'm using a nice enough cms (locomotive(github)) to allow some non-tech savy users to upload pictures to the system. The program is able to resize and crop pictures to any given size.

Trouble is, Internet explorer doesn't know how to deal with CMYK-encoded images. The users of this app are not exactly tech-savy; asking them to transform their images from CMYK to RGB is not an option. I'd like to modify locomotive so that it does the change automatically. I've been trying this for some hours but had no luck so far.

This is what I have found:

  • Locomotive uses dragonfly to perform the resizing.
  • Concretely, it uses dragonfly's imagemagick module.
  • The file that defines how Dragonfly is used in locomotive can be found here.
  • There is also a dragonfly initializer file.

I have also found that what (think) I need is adding a -colorspace RGB option to the parameter sent to Imagemagick by Dragonfly. It doesn't look like Dragonfly provides an easy option to do that.

I've tried several things, the last one consisting on monkeypatching Dragonfly's Imagemagick Processor so that the -colorspace RGB option is always used. I've added this in locomotive's config/initializers/dragonfly.rb:

# locomotive's config/initializers/dragonfly.rb

# ... Locomotive's default initialization

module Dragonfly
  module ImageMagick
    class Processor
      alias :old_convert :convert
      def convert(temp_object, args='', format=nil)
        args += ' -colorspace RGB' # force RGB in all thumbnails 
        old_convert(temp_object, args, format)
      end
    end
  end
end

I was pretty sure that this should work, but unfortunately it doesn't. And I have run out of ideas. Can anyone help?

Was it helpful?

Solution 3

Unfortunately there doesn't seem to be a straightforward way to do this with Dragonfly. I've given up.

OTHER TIPS

On the commandline, I sometimes need to add -type truecolor to make colorspace conversions work reliably:

convert cmyk.jpeg -colorspace rgb -type truecolor rgb.jpeg

Maybe you try to add it in your code as well?

From the related list to the right, might this SO answer help?

Properly converting a CMYK image to RGB with RMagick

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top