Module: AttachmerbFu::Processors::RmagickProcessor::ClassMethods

Defined in:
lib/attachmerb_fu/processors/rmagick_processor.rb

Instance Method Summary collapse

Instance Method Details

#with_image(file, &block) ⇒ Object

Yields a block containing an RMagick Image for the given binary data.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/attachmerb_fu/processors/rmagick_processor.rb', line 12

def with_image(file, &block)
  begin
    binary_data = file.is_a?(Magick::Image) ? file : Magick::Image.read(file).first unless !Object.const_defined?(:Magick)
  rescue
    # Log the failure to load the image.  This should match ::Magick::ImageMagickError
    # but that would cause acts_as_attachment to require rmagick.
    logger.debug("Exception working with image: #{$!}")
    binary_data = nil
  end
  block.call binary_data if block && binary_data
ensure
  !binary_data.nil?
end