Skip to content

How to: Specify the image quality

clyfe edited this page May 27, 2011 · 4 revisions

If you want to set the image quality, create a file config/initializers/carrierwave.rb with the following content:

module CarrierWave
  module RMagick

    def quality(percentage)
      manipulate! do |img|
        img.write(current_path){ self.quality = percentage } unless img.quality == percentage
        img = yield(img) if block_given?
        img
      end
    end

  end
end

Now you can use the process :quality in your uploaders:

class AvatarUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  
  version :thumb do
    process :resize_to_fit => [100, 100]
    process :quality => 100 
  end
end
Clone this wiki locally