lib/carrierwave/processing/rmagick.rb in carrierwave-0.4.3 vs lib/carrierwave/processing/rmagick.rb in carrierwave-0.4.4

- old
+ new

@@ -74,11 +74,11 @@ base.extend(ClassMethods) end module ClassMethods def convert(format) - process :resize_to_limit => format + process :convert => format end def resize_to_limit(width, height) process :resize_to_limit => [width, height] end @@ -89,14 +89,10 @@ def resize_to_fill(width, height) process :resize_to_fill => [width, height] end - def resize_and_pad(width, height) - process :resize_to_fit => [width, height] - end - def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity) process :resize_and_pad => [width, height, background, gravity] end end @@ -116,15 +112,11 @@ # === Examples # # image.convert(:png) # def convert(format) - manipulate! do |img| - img.format = format.to_s.upcase - img = yield(img) if block_given? - img - end + manipulate!(:format => format) end ## # Resize the image to fit within the specified dimensions while retaining # the original aspect ratio. Will only resize the image if it is larger than the @@ -253,24 +245,30 @@ # # === Raises # # [CarrierWave::ProcessingError] if manipulation failed. # - def manipulate! + def manipulate!(options={}) image = ::Magick::Image.read(current_path) - if image.size > 1 + frames = if image.size > 1 list = ::Magick::ImageList.new image.each do |frame| list << yield( frame ) end - list.write(current_path) - destroy_image(list) + list else frame = image.first - yield( frame ).write(current_path) - destroy_image(frame) + frame = yield( frame ) if block_given? + frame end + + if options[:format] + frames.write("#{options[:format]}:#{current_path}") + else + frames.write(current_path) + end + destroy_image(frames) rescue ::Magick::ImageMagickError => e raise CarrierWave::ProcessingError.new("Failed to manipulate with rmagick, maybe it is not an image? Original Error: #{e}") end private