Search code examples
ruby-on-railsrubycarrierwaveminimagick

In carrierwave, strip image but keep color profile OR convert color profile to sRGB


I'm having basically the same problem here:

How to remove exif from a JPG without losing image quality?

But I'm using Rails and Carrierwave. I'm not sure how Robbert's solution converts to Ruby.

Any help would greatly be appreciated! Thanks!


Solution

  • From the carrierwave docs, you can add something like the following mogrify function to your uploader:

    class PhotoUploader < CarrierWave::Uploader::Base
      include CarrierWave::MiniMagick
    
      process :mogrify
    
      # ...
    
      def mogrify
        manipulate! do |img|
          img.format('jpg') do |c|
    
            # other options you may want, eg:
            # c.auto_orient
    
            convert.profile.+('!icc,!xmp,*')
          end
          img
        end
      end
    end
    

    which will strip the EXIF data but preserve the ICC and XMP profiles in the JPG.