Created
June 4, 2013 01:01
-
-
Save dleavitt/5702816 to your computer and use it in GitHub Desktop.
Additional image processors for carrierwave+minimagick
This file contains hidden or 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
module CarrierWave | |
module MiniMagick | |
module ImageProcessors | |
def store_dimensions(property_name) | |
# TODO: deal with default version | |
image = ::MiniMagick::Image.open(current_path) | |
model.send("#{property_name}=", {}) unless model.send(property_name) | |
ver = (version_name || "original").to_s | |
model.send(property_name)[ver] = image["dimensions"] | |
end | |
def auto_orient | |
manipulate! do |img| | |
img.auto_orient | |
img = yield(img) if block_given? | |
img | |
end | |
end | |
def strip | |
manipulate! do |img| | |
img.strip | |
img = yield(img) if block_given? | |
img | |
end | |
end | |
def resize_to_fill_width(width, height, gravity = "center") | |
manipulate! do |img| | |
img.resize width | |
cols, rows = img[:dimensions] | |
if rows > height | |
img.gravity "Center" | |
img.extent "#{width}x#{height}" | |
end | |
img | |
end | |
end | |
def extension_white_list | |
%w( jpg jpeg gif png ) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment