Skip to content

Instantly share code, notes, and snippets.

@chechaoyang
Created May 5, 2011 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chechaoyang/956795 to your computer and use it in GitHub Desktop.
Save chechaoyang/956795 to your computer and use it in GitHub Desktop.
Paperclip Watermarking
# from https://github.com/mpelos/nova_marine/blob/2dc882dac31532024d4edb196e4a632801738341/lib/paperclip_processors/watermark.rb
# Rails.root /lib/paperclip_processors/watermark.rb
module Paperclip
class Watermark < Thumbnail
def initialize(file, options = {}, attachment = nil)
super
@watermark_path = options[:watermark_path]
@position = options[:position].nil? ? "SouthEast" : options[:position]
end
def make
src = @file
dst = Tempfile.new([@basename].compact.join("."))
dst.binmode
return super unless @watermark_path
params = ":source #{transformation_command.join(" ")} #{@watermark_path} -gravity #{@position} -composite :dest"
begin
success = Paperclip.run("convert", params, :source => "#{File.expand_path(src.path)}[0]", :dest => File.expand_path(dst.path))
rescue PaperclipCommandLineError
raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny
end
dst
end
end
end
@joshuapinter
Copy link

Is this meant to replace the thumbnail processor and you just use this instead?

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