In my application, I use mini_magick and I need to convert images to black and white and sepia tones. In Rails 1,2,3, this used to work:
after_resize do |record,img| logger.debug "img = #{img}" logger.debug "record = #{record}" logger.debug "self = #{self}" logger.debug "record.thumbnail = #{record.thumbnail}" if record.thumbnail.to_s.match(/.*_bw/) img.combine_options do |i| i.colors("256") i.colorspace(:GRAY) i.colorspace(:RGB) i.quality 100 end end
if record.thumbnail.to_s.match(/.*sepia/) img.combine_options do |i| i.colors("256") i.colorspace(:GRAY) i.colorspace(:RGB) i.fill "#cc9933" i.colorize "30/30/30" i.quality 100 end end
end
Now that I'm trying to use Rails 2.1, the log file says:
img = record = #<MiniMagick::Image:0x20e43ac> self = Photo
SQL (0.000471) ROLLBACK ApplicationProcessor::on_error: MiniMagick::MiniMagickError rescued: ImageMagick command (mogrify -thumbnail "/var/folders/w2/w2+1jcd4Ge0d24HOVnPL2++++TI/-Tmp-/minimagick5822-1") failed: Error Given 256 /Library/Ruby/Gems/1.8/gems/mini_magick-1.2.3/lib/mini_magick.rb:124:in `run_command' /Library/Ruby/Gems/1.8/gems/mini_magick-1.2.3/lib/mini_magick.rb:93:in `method_missing' /Users/matt/Sites/checkout/app/models/photo.rb:28 /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:177:in `call' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:177:in `evaluate_method' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:161:in `call' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:93:in `run' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in `each' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in `send' /Users/matt/Sites/checkout/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/callbacks.rb:92:in `run' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:451:in `run_callbacks' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:440:in `callback_with_args' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:34:in `process_attachment' /Users/matt/Sites/checkout/vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu/processors/mini_magick_processor.rb:21:in . . .
So, it seems that the callback is only getting one argument. And it's getting the mini_magick::Image in the place where it is supposed to get the record.
I've spent quite a bit of time looking at attachment_fu.rb around line 437 (callback_with_args) to try to figure out how this works, and I'm wondering if anybody else is having any success with attachment_fu and rails 2.1? Are you getting both parameters passed to your callback?
Thanks,
Matt