Skip to content

Instantly share code, notes, and snippets.

@stream7
Forked from mariovisic/avatar_uploader.rb
Created October 13, 2011 14:29
Show Gist options
  • Save stream7/1284343 to your computer and use it in GitHub Desktop.
Save stream7/1284343 to your computer and use it in GitHub Desktop.
# app/uploaders/avatar_uploader.rb
process :fix_exif_rotation
process :strip
process :resize_to_fill => [1024, 768]
process :quality => 90 # Percentage from 0 - 100
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment