Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Created March 25, 2013 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save soulcutter/b3182af2db0357199040 to your computer and use it in GitHub Desktop.
Save soulcutter/b3182af2db0357199040 to your computer and use it in GitHub Desktop.
# ... other initialization stuff above here ...
Dragonfly[:images].processor.register(Watermark)
# optional, but gives you the ability to use watermark(opacity: 50)
# rather than process(:watermark, opacity: 50)
Dragonfly[:images].configure do |c|
c.job(:watermark) { |*args| process(:watermark, *args) }
end
@luopio
Copy link

luopio commented Jul 15, 2015

I couldn't get this to work on Dragonfly 1.0.10 and after some digging I ended up coding the following solution that only requires an initializer file:

# config/initializers/dragonfly.rb
require 'dragonfly'

Dragonfly.app.configure do
  processor :watermark do |content, *args|
    args    = args.first || {}
    opacity = args[:opacity] || 40
    watermark = File.new(File.dirname(__FILE__) + "relative/path/to/watermark.png").path
    content.process! :convert, "#{watermark } -compose dissolve -define compose:args=#{opacity}% -gravity southwest -geometry +20+20 -composite"
  end
end

@soulcutter
Copy link
Author

@luopio Yes, the API has changed since the writing of this gist. Thanks for sharing your version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment