2 module Technoweenie # :nodoc:
3 module AttachmentFu # :nodoc:
5 module MiniMagickProcessor
6 def self.included(base)
7 base.send :extend, ClassMethods
8 base.alias_method_chain :process_attachment, :processing
12 # Yields a block containing an MiniMagick Image for the given binary data.
13 def with_image(file, &block)
15 binary_data = file.is_a?(MiniMagick::Image) ? file : MiniMagick::Image.from_file(file) unless !Object.const_defined?(:MiniMagick)
17 # Log the failure to load the image.
18 logger.debug("Exception working with image: #{$!}")
21 block.call binary_data if block && binary_data
28 def process_attachment_with_processing
29 return unless process_attachment_without_processing
31 resize_image_or_thumbnail! img
32 self.width = img[:width] if respond_to?(:width)
33 self.height = img[:height] if respond_to?(:height)
34 callback_with_args :after_resize, img
38 # Performs the actual resizing operation for a thumbnail
39 def resize_image(img, size)
40 size = size.first if size.is_a?(Array) && size.length == 1
41 if size.is_a?(Fixnum) || (size.is_a?(Array) && size.first.is_a?(Fixnum))
44 img.resize(size.join('x'))
46 img.resize(size.join('x') + '!')