Technology and Software

CMYK jpegs and Paperclip (Ruby on Rails)

I just discovered that not all jpegs are made equal. There are jpegs that use the RGB colorspace and others that use the CMYK colorspace. RGB is more common and Internet Explorer can’t handle the CMYK ones: it displays the icon of a broken/unloaded image instead. Another reason to hope it soon fades away but many people still use it.

The solution? If you’re a content producer: create RGB jpegs. If you let people upload pictures on your site: convert pictures to RGB. This is how I did it in my latest Ruby onĀ  Rails application which uses Paperclip to handle uploads.

Put this code into lib/paperclip_processors/colorspace.rb (edit: that was for Paperclip 2.3.1.1, check the comments for how to fix than in newer versions)

module Paperclip
  class Colorspace < Thumbnail
    def transformation_command
      " -colorspace RGB " + super
    end
  end
end

Add this line to your model, as an argument of has_attached_file

:processors => [:colorspace],

That’s it. For a discussion about CMYK images and Internet Explorer read this.

Advertisements
Standard