Class: Paperclip::Watermark
- Inherits:
-
Processor
- Object
- Processor
- Paperclip::Watermark
- Defined in:
- lib/paperclip_processors/watermark.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
Handles watermarking of images that are uploaded.
-
#position ⇒ Object
Handles watermarking of images that are uploaded.
-
#watermark_path ⇒ Object
Handles watermarking of images that are uploaded.
-
#whiny ⇒ Object
Handles watermarking of images that are uploaded.
Instance Method Summary collapse
- #fromfile ⇒ Object
-
#initialize(file, options = {}, attachment = nil) ⇒ Watermark
constructor
A new instance of Watermark.
-
#make ⇒ Object
Performs the conversion of the
file
into a watermark. - #tofile(destination) ⇒ Object
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Watermark
Returns a new instance of Watermark.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/paperclip_processors/watermark.rb', line 11 def initialize file, = {}, = nil super @file = file @whiny = [:whiny].nil? ? true : [:whiny] @format = [:format] @watermark_path = [:watermark_path] @position = [:watermark_position].nil? ? "SouthEast" : [:watermark_position] @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) end |
Instance Attribute Details
#format ⇒ Object
Handles watermarking of images that are uploaded.
9 10 11 |
# File 'lib/paperclip_processors/watermark.rb', line 9 def format @format end |
#position ⇒ Object
Handles watermarking of images that are uploaded.
9 10 11 |
# File 'lib/paperclip_processors/watermark.rb', line 9 def position @position end |
#watermark_path ⇒ Object
Handles watermarking of images that are uploaded.
9 10 11 |
# File 'lib/paperclip_processors/watermark.rb', line 9 def watermark_path @watermark_path end |
#whiny ⇒ Object
Handles watermarking of images that are uploaded.
9 10 11 |
# File 'lib/paperclip_processors/watermark.rb', line 9 def whiny @whiny end |
Instance Method Details
#fromfile ⇒ Object
43 44 45 |
# File 'lib/paperclip_processors/watermark.rb', line 43 def fromfile "\"#{ File.(@file.path) }[0]\"" end |
#make ⇒ Object
Performs the conversion of the file
into a watermark. Returns the Tempfile that contains the new image.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/paperclip_processors/watermark.rb', line 25 def make return @file unless watermark_path dst = Tempfile.new([@basename, @format].compact.join(".")) dst.binmode command = "composite" params = "-gravity #{@position} #{watermark_path} #{fromfile} #{tofile(dst)}" begin success = Paperclip.run(command, params) rescue PaperclipCommandLineError raise PaperclipError, "There was an error processing the watermark for #{@basename}" if @whiny end dst end |
#tofile(destination) ⇒ Object
47 48 49 |
# File 'lib/paperclip_processors/watermark.rb', line 47 def tofile(destination) "\"#{ File.(destination.path) }[0]\"" end |