lib/carrierwave/processing/rmagick.rb in carrierwave-0.11.2 vs lib/carrierwave/processing/rmagick.rb in carrierwave-1.0.0.beta
- old
+ new
@@ -1,7 +1,5 @@
-# encoding: utf-8
-
module CarrierWave
##
# This module simplifies manipulation with RMagick by providing a set
# of convenient helper methods. If you want to use them, you'll need to
@@ -250,10 +248,32 @@
new_img
end
end
##
+ # Returns the width of the image.
+ #
+ # === Returns
+ #
+ # [Integer] the image's width in pixels
+ #
+ def width
+ rmagick_image.columns
+ end
+
+ ##
+ # Returns the height of the image.
+ #
+ # === Returns
+ #
+ # [Integer] the image's height in pixels
+ #
+ def height
+ rmagick_image.rows
+ end
+
+ ##
# Manipulate the image with RMagick. This method will load up an image
# and then pass each of its frames to the supplied block. It will then
# save the image to disk.
#
# === Gotcha
@@ -322,15 +342,19 @@
frames << frame if frame
end
frames.append(true) if block_given?
write_block = create_info_block(options[:write])
+
if options[:format] || @format
frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
+ move_to = current_path.chomp(File.extname(current_path)) + ".#{options[:format] || @format}"
+ file.move_to(move_to, permissions, directory_permissions)
else
frames.write(current_path, &write_block)
end
+
destroy_image(frames)
rescue ::Magick::ImageMagickError => e
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e, :default => I18n.translate(:"errors.messages.rmagick_processing_error", :e => e, :locale => :en))
end
@@ -342,10 +366,14 @@
code = "lambda { |img| " + assignments.join(";") + "}"
eval code
end
def destroy_image(image)
- image.destroy! if image.respond_to?(:destroy!)
+ image.try(:destroy!)
+ end
+
+ def rmagick_image
+ ::Magick::Image.read(current_path).first
end
end # RMagick
end # CarrierWave