Class: Paperclip::PapermillPaperclipProcessor
- Inherits:
-
Thumbnail
- Object
- Thumbnail
- Paperclip::PapermillPaperclipProcessor
- Defined in:
- lib/papermill/papermill_paperclip_processor.rb
Overview
Handles thumbnailing images that are uploaded.
Instance Attribute Summary collapse
-
#copyright ⇒ Object
Returns the value of attribute copyright.
-
#crop_h ⇒ Object
Returns the value of attribute crop_h.
-
#crop_w ⇒ Object
Returns the value of attribute crop_w.
-
#crop_x ⇒ Object
Returns the value of attribute crop_x.
-
#crop_y ⇒ Object
Returns the value of attribute crop_y.
-
#watermark_path ⇒ Object
Returns the value of attribute watermark_path.
Instance Method Summary collapse
- #copyright_command ⇒ Object
- #crop_command ⇒ Object
-
#initialize(file, options = {}, attachment = nil) ⇒ PapermillPaperclipProcessor
constructor
A new instance of PapermillPaperclipProcessor.
- #transformation_command ⇒ Object
- #watermark_command ⇒ Object
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ PapermillPaperclipProcessor
Returns a new instance of PapermillPaperclipProcessor.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 10 def initialize(file, = {}, = nil) @crop_h, @crop_w, @crop_x, @crop_y = [:crop_h], [:crop_w], [:crop_x], [:crop_y] # copyright extraction if [:geometry] =~ /©/ || [:copyright] [:geometry], *@copyright = [:geometry].split("©", -1) @copyright = ( ([:copyright] != true && [:copyright]) || @copyright.join("©").nie || file.instance.respond_to?(:copyright) && file.instance.copyright.nie || file.instance.[:copyright].nie) if @copyright @copyright = ([:copyright_text_transform] || file.instance.[:copyright_text_transform]).try(:call, @copyright) || @copyright end end # watermark extraction if [:watermark] || [:geometry] =~ /\-wm/ [:geometry] = [:geometry].chomp("-wm") @watermark_path = [:watermark].is_a?(String) && [:watermark] || file.instance.[:watermark] @watermark_path = "#{RAILS_ROOT}/public" + @watermark_path if @watermark_path.starts_with?("/") end if [:geometry] =~ /#.+/ # let's parse : # <width>x<height>#<crop_w>x<crop_h>:<crop_x>:<crop_y> # <width>x<height>#<crop_w>x<crop_h> # <width>x<height>#<crop_x>:<crop_y> [:geometry], manual_crop = [:geometry].split("#") crop_dimensions, @crop_x, @crop_y = manual_crop.split("+") if crop_dimensions =~ /x/ @crop_w, @crop_h = crop_dimensions.split("x") else @crop_x, @crop_y = crop_dimensions, @crop_x end [:geometry] = ([:geometry].nie || "#{@crop_x}x#{@crop_y}") + "#" unless @crop_w && @crop_h @target_geometry = Geometry.parse([:geometry]) @crop_w ||= @target_geometry.try(:width).to_i @crop_h ||= @target_geometry.try(:height).to_i end end super end |
Instance Attribute Details
#copyright ⇒ Object
Returns the value of attribute copyright.
8 9 10 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 8 def copyright @copyright end |
#crop_h ⇒ Object
Returns the value of attribute crop_h.
8 9 10 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 8 def crop_h @crop_h end |
#crop_w ⇒ Object
Returns the value of attribute crop_w.
8 9 10 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 8 def crop_w @crop_w end |
#crop_x ⇒ Object
Returns the value of attribute crop_x.
8 9 10 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 8 def crop_x @crop_x end |
#crop_y ⇒ Object
Returns the value of attribute crop_y.
8 9 10 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 8 def crop_y @crop_y end |
#watermark_path ⇒ Object
Returns the value of attribute watermark_path.
8 9 10 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 8 def watermark_path @watermark_path end |
Instance Method Details
#copyright_command ⇒ Object
66 67 68 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 66 def copyright_command ([:copyright_im_command] || @file.instance.[:copyright_im_command]).gsub(/%s/, @copyright.gsub(/'/, %{'"'"'}).sub("-slash-", "/").sub("-backslash-", %{\\\\\\})) if @copyright end |
#crop_command ⇒ Object
74 75 76 77 78 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 74 def crop_command if @crop_h || @crop_x " -crop '%dx%d+%d+%d'" % [ @crop_w, @crop_h, @crop_x, @crop_y ].map(&:to_i) end end |
#transformation_command ⇒ Object
62 63 64 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 62 def transformation_command " -limit memory 1 -limit map 1 #{(crop_command ? super.sub(/ -crop \S+/, crop_command) : super)} #{copyright_command} #{watermark_command}".sub(%{-resize "0x" }, "") end |
#watermark_command ⇒ Object
70 71 72 |
# File 'lib/papermill/papermill_paperclip_processor.rb', line 70 def watermark_command ([:watermark_im_command] || @file.instance.[:watermark_im_command]).gsub(/%s/, @watermark_path) if @watermark_path end |