Hello,
Recently attachment_fu stopped resizing images for me. I’m puzzled
because before today it was resizing them and I don’t know what’s
changed. Here’s my code:
class Product < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 18.megabytes,
:resize_to => ‘300x’,
:thumbnails => { :thumb => ‘61x110!’ }
validates_as_attachment
end
I expected a 420x595 image to be resized to 300xWhatever and a 61x110
thumbnail to be created. The image and thumbnail product records
were both created in the database but the images were left at the
original size.
Strangely the width and height fields in the database are no longer
being set. For new uploads they are null whereas previously they had
been set to the measurements of the resized images.
I think I’ve traced the problem to this method (but I could equally
well be barking up the wrong tree):
attachment_fu/processors/rmagick_processor.rb:
module ClassMethods
# Yields a block containing an RMagick Image for the given
binary data.
def with_image(file, &block)
begin
binary_data = file.is_a?(Magick::Image) ? file :
Magick::Image.read(file).first unless !Object.const_defined?(:Magick)
puts “binary_data.nil? : #{binary_data.nil?}”
puts “file.nil?: #{file.nil?}”
puts “const_defined? : #{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
end
My puts statements give this output:
binary_data.nil? : true
file.nil?: false
const_defined? : false
So it looks like the undefined constant prevents binary_data from
being assigned. But I don’t know what to do about this.
I’d appreciate any help.
Thanks and regards,
Andy S.