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

3 thoughts on “CMYK jpegs and Paperclip (Ruby on Rails)

  1. jesper says:

    and this works for me in the current version of Paperclip:

    module Paperclip
    class Colorspace < Thumbnail
    def transformation_command
    trans = []
    trans << super
    trans << "-colorspace RGB"
    end
    end
    end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s