Using :convert_options to add a watermark

69 views
Skip to first unread message

Kyle

unread,
Mar 31, 2011, 11:21:03 AM3/31/11
to Paperclip Plugin
Im trying to add a watermark to all uploaded photos
using :convert_options

Here is my model for images:

has_attached_file :photo,
#:convert_options => {:blog =>"-dissolve 25% -gravity south
#{RAILS_ROOT}/public/images/watermark.png"},
:styles => {:thumb => "100x100#", :small => "150x150X", :blog =>
"550x550>",
:primary =>"700x700>" }

but Im getting a paperclip error in the console:
PaperclipError: There was an error processing the thumbnail for stream

I guess Im not passing something in correctly or leaving something
out? The imagemagick documentation looks like it gets the watermark,
original image, and watermarked image passed in but Im not sure how to
do that with paperclip.

Gordon Yeong

unread,
Mar 31, 2011, 8:18:24 PM3/31/11
to papercli...@googlegroups.com
Hi there,
  Here's how I did mine (ie. getting watermarks applied to uploaded images as well as resizing them).
 Hope it helps :)


  

class Image < ActiveRecord::Base
  belongs_to :blog_posts

  has_attached_file :info,
    :processors => [:watermark],
    :styles => {
      :mini     => "60x60#",
      :thumb    => "160x160#",
      :medium   =>  {
        :geometry => "600>",
        :watermark_path => "#{RAILS_ROOT}/public/images/watermark_image.png",
        :position => "SouthEast"
      },
      :original => "1x1"

    }

 validate :check_content_type

 def check_content_type
   if !['image/jpeg', 'image/pjpeg', 'image/x-png', 'image/gif', 'image/png'].include?(self.info_content_type)
     errors.add( 'attachment,', "'#{self.info_file_name}' is not a valid image type")
   end
 end

end



Best wishes,
Gordon Yeong


--
Individuals over processes. Interactions over tools.

Agile Rails training from thoughtbot, the makers of Paperclip, Clearance, Shoulda, & Factory Girl:
http://thoughtbot.com/services/training

The Paperclip group:
http://groups.google.com/group/paperclip-plugin

To post to this group, send email to
papercli...@googlegroups.com

To unsubscribe from this group, send email to
paperclip-plug...@googlegroups.com

Kyle

unread,
Mar 31, 2011, 9:09:23 PM3/31/11
to Paperclip Plugin
I think that watermark is broken in rails3 and paperclip 2.3

Ive tried this before and got an uninitialized method error for
watermark. There are a few modified modules like:
http://exviva.posterous.com/watermarking-images-with-rails-3-and-papercli

and:
https://gist.github.com/raw/465088/3de6e4f50ff659b91ee094764af842968d4e0de3/watermark.rb.
(these first two give me an error: wrong number of arguments (5 for
3))
and:
https://gist.github.com/784445
(get some nil object error.

So Im at a loss and someone suggested just throwing in some
imagemagick commands at it but yea, Im still pretty new to RoR :/
Reply all
Reply to author
Forward
0 new messages