Class: Paperclip::Watermark
- Inherits:
-
Processor
- Object
- Processor
- Paperclip::Watermark
- Defined in:
- lib/watermark_paperclip_processor/watermark.rb
Instance Attribute Summary collapse
-
#convert_options ⇒ Object
Returns the value of attribute convert_options.
-
#current_geometry ⇒ Object
Returns the value of attribute current_geometry.
-
#format ⇒ Object
Returns the value of attribute format.
-
#overlay ⇒ Object
Returns the value of attribute overlay.
-
#position ⇒ Object
Returns the value of attribute position.
-
#target_geometry ⇒ Object
Returns the value of attribute target_geometry.
-
#watermark_path ⇒ Object
Returns the value of attribute watermark_path.
-
#whiny ⇒ Object
Returns the value of attribute whiny.
Instance Method Summary collapse
-
#convert_options? ⇒ Boolean
Returns true if the image is meant to make use of additional convert options.
-
#crop? ⇒ Boolean
Returns true if the
target_geometry
is meant to crop. - #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
- #transformation_command ⇒ Object
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Watermark
Returns a new instance of Watermark.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 6 def initialize file, = {}, = nil super geometry = [:geometry] @file = file @crop = geometry[-1,1] == '#' @target_geometry = Geometry.parse geometry @current_geometry = Geometry.from_file @file @convert_options = [:convert_options] @whiny = [:whiny].nil? ? true : [:whiny] @format = [:format] @watermark_path = [:watermark_path] @position = [:position].nil? ? "SouthEast" : [:position] @overlay = [:overlay].nil? ? true : false @current_format = File.extname(@file.path) @basename = File.basename(@file.path, @current_format) end |
Instance Attribute Details
#convert_options ⇒ Object
Returns the value of attribute convert_options.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def @convert_options end |
#current_geometry ⇒ Object
Returns the value of attribute current_geometry.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def current_geometry @current_geometry end |
#format ⇒ Object
Returns the value of attribute format.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def format @format end |
#overlay ⇒ Object
Returns the value of attribute overlay.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def @overlay end |
#position ⇒ Object
Returns the value of attribute position.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def position @position end |
#target_geometry ⇒ Object
Returns the value of attribute target_geometry.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def target_geometry @target_geometry end |
#watermark_path ⇒ Object
Returns the value of attribute watermark_path.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def watermark_path @watermark_path end |
#whiny ⇒ Object
Returns the value of attribute whiny.
4 5 6 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 4 def whiny @whiny end |
Instance Method Details
#convert_options? ⇒ Boolean
Returns true if the image is meant to make use of additional convert options.
29 30 31 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 29 def not @convert_options.blank? end |
#crop? ⇒ Boolean
Returns true if the target_geometry
is meant to crop.
24 25 26 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 24 def crop? @crop end |
#fromfile ⇒ Object
53 54 55 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 53 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 35 def make dst = Tempfile.new([@basename, @format].compact.join(".")) dst.binmode if watermark_path command = "composite" params = "-gravity #{@position} #{watermark_path} #{fromfile} #{transformation_command} #{tofile(dst)}" else command = "convert" params = "#{fromfile} #{transformation_command} #{tofile(dst)}" end 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
57 58 59 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 57 def tofile(destination) "\"#{ File.(destination.path) }[0]\"" end |
#transformation_command ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/watermark_paperclip_processor/watermark.rb', line 61 def transformation_command scale, crop = @current_geometry.transformation_to(@target_geometry, crop?) trans = "-resize \"#{scale}\"" trans << " -crop \"#{crop}\" +repage" if crop trans << " #{}" if trans end |