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... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
kevin evans wrote:> Hi,> > Anyone have an ideas on how to achieve this? > > thanks in advance...Besides public_filename there are other methods within the Attachment_fu'' modified model that you can get at.. I don''t remember off the top of my head what it''s name is but you can do the following to find out script/console> Picture.instance_methods.grep /path/One of those methods should get you an absolute path in which your after_save filter should work.. I haven''t done this myself (other than using the alternate path methods) and it''s only the path I would take myself.. hth ilan -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
andrew.ohnstad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Mar-03 14:41 UTC
Re: Attachment_fu, Watermarks and after_save
I have the exact same code as you do, and it works pefectly. Actually, I also have ''unless self.thumbnail?'' at the beginning of that code block because I was getting my fullsize logo on top of my thumbnails as well, but that''s a different story. I would check your paths to make sure that things are where you expect them. ''after save'' is, well, after the record/file is saved, so I would look elsewhere for your problem. When you''re looking at the error page, are you 1000% sure that the path shown for the error page exists and is valid? On Mar 2, 6:26 pm, kevin evans <kwev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---