Skip to content

Instantly share code, notes, and snippets.

@talyric
Forked from iqbalhasnan/carrierwave.rb
Created January 22, 2016 22:48
Show Gist options
  • Save talyric/640272253bd97026391b to your computer and use it in GitHub Desktop.
Save talyric/640272253bd97026391b to your computer and use it in GitHub Desktop.
carrierwave mini_magick image processing - quality, strip, exif rotation, gaussian blur, interlace
#config/initializers/carrierwave.rb
module CarrierWave
module MiniMagick
# Rotates the image based on the EXIF Orientation
def 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
# Tiny gaussian blur to optimize the size
def gaussian_blur(radius)
manipulate! do |img|
img.gaussian_blur(radius.to_s)
img = yield(img) if block_given?
img
end
end
# set the Interlace of the image plane/basic
def interlace(type)
manipulate! do |img|
img.interlace(type.to_s)
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.quality(percentage.to_s)
img = yield(img) if block_given?
img
end
end
end
end
# fix exif rotation before strip the exif data
process :fix_exif_rotation
process :strip
# set gaussion blur to optimize the image
process :gaussian_blur => 0.05
# default quality is 85
# process :quality => 85 # Percentage from 0 - 100
# set the interlace to plane for progressive jpeg
# this might increase the size of images a bit
process :interlace => Plane
# Create 820x820 fill image size
version :medium do
process :resize_to_limit => [820, 820]
process :interlace => Plane
# Create 380x380 fill image size
end
version :small do
process :resize_to_limit => [380, 380]
process :interlace => Plane
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment