Created
May 11, 2011 05:39
-
-
Save mariovisic/965983 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/uploaders/avatar_uploader.rb | |
process :fix_exif_rotation | |
process :strip | |
process :resize_to_fill => [1024, 768] | |
process :quality => 90 # Percentage from 0 - 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/carrierwave_initializer.rb | |
module CarrierWave | |
module RMagick | |
# Rotates the image based on the EXIF Orientation | |
def fix_exif_rotation | |
manipulate! do |img| | |
img.auto_orient! | |
img = yield(img) if block_given? | |
img | |
end | |
end | |
# Strips out all embedded information from the image | |
def strip | |
manipulate! do |img| | |
img.strip! | |
img = yield(img) if block_given? | |
img | |
end | |
end | |
# Reduces the quality of the image to the percentage given | |
def quality(percentage) | |
manipulate! do |img| | |
img.write(current_path){ self.quality = percentage } | |
img = yield(img) if block_given? | |
img | |
end | |
end | |
end | |
end |
Is there a version for MiniMagick
? :)
Really cool! for MiniMagick, should change the auto_orient! to auto_orient
FYI, how to do this in just an uploader class: http://stackoverflow.com/a/4767021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noted that when using #strip! some images with exotic color profiles got a bit darker.