lib/carrierwave/processing/rmagick.rb in carrierwave-1.1.0 vs lib/carrierwave/processing/rmagick.rb in carrierwave-1.2.0
- old
+ new
@@ -131,10 +131,12 @@
# === Yields
#
# [Magick::Image] additional manipulations to perform
#
def resize_to_limit(width, height)
+ width = dimension_from width
+ height = dimension_from height
manipulate! do |img|
geometry = Magick::Geometry.new(width, height, 0, 0, Magick::GreaterGeometry)
new_img = img.change_geometry(geometry) do |new_width, new_height|
img.resize(new_width, new_height)
end
@@ -160,10 +162,12 @@
# === Yields
#
# [Magick::Image] additional manipulations to perform
#
def resize_to_fit(width, height)
+ width = dimension_from width
+ height = dimension_from height
manipulate! do |img|
img.resize_to_fit!(width, height)
img = yield(img) if block_given?
img
end
@@ -184,10 +188,12 @@
# === Yields
#
# [Magick::Image] additional manipulations to perform
#
def resize_to_fill(width, height, gravity=::Magick::CenterGravity)
+ width = dimension_from width
+ height = dimension_from height
manipulate! do |img|
img.crop_resized!(width, height, gravity)
img = yield(img) if block_given?
img
end
@@ -209,10 +215,12 @@
# === Yields
#
# [Magick::Image] additional manipulations to perform
#
def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
+ width = dimension_from width
+ height = dimension_from height
manipulate! do |img|
img.resize_to_fit!(width, height)
new_img = ::Magick::Image.new(width, height) { self.background_color = background == :transparent ? 'rgba(255,255,255,0)' : background.to_s }
if background == :transparent
filled = new_img.matte_floodfill(1, 1)
@@ -369,11 +377,16 @@
def destroy_image(image)
image.try(:destroy!)
end
+ def dimension_from(value)
+ return value unless value.instance_of?(Proc)
+ value.arity >= 1 ? value.call(self) : value.call
+ end
+
def rmagick_image
- ::Magick::Image.read(current_path).first
+ ::Magick::Image.from_blob(self.read).first
end
end # RMagick
end # CarrierWave