Hi,
I’m having an issue with trying to watermark an uploaded image using
attachment_fu and Rails 2.0.2.
The model looks like…
class Picture < ActiveRecord::Base
belongs_to :gallery
after_save :watermark_image
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 2.megabytes,
:resize_to => ‘500x500’,
:processor => “Rmagick”,
:thumbnails => {
:large => ‘128x128>’,
:small => ‘64x64>’
}
validates_as_attachment
def watermark_image
dst = Magick::Image.read("#{RAILS_ROOT}/
public#{self.public_filename}").first
src = Magick::Image.read("#{RAILS_ROOT}/config/Logo.png").first
result = dst.composite(src, Magick::SouthEastGravity,
Magick::OverCompositeOp)
result.write("#{RAILS_ROOT}/public#{self.public_filename}")
end
end
The code fails with a ‘Cannot read image’ on the ‘dst = …’ line of
the watermark_image method.
Looks like the file does not actually exist in the file system until
after ‘after_save’?
removing the ‘after_save’ and all works, except of course no
watermark…
Anyone have an ideas on how to achieve this?
thanks in advance…