forked from carrierwaveuploader/carrierwave
-
Notifications
You must be signed in to change notification settings - Fork 2
How to: Specify the image quality
idavemm edited this page Feb 17, 2012
·
3 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
# put this in config/initializers/carrierwave.rb
module CarrierWave
module MiniMagick
def quality(percentage)
manipulate! do |img|
img.quality(percentage.to_s)
img = yield(img) if block_given?
img
end
end
end
end
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process :quality => 85
version :medium do
process :quality => 85
end
end