Class: Imageproxy::Convert
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #convert_options ⇒ Object
- #execute(user_agent = nil, timeout = nil) ⇒ Object
- #file ⇒ Object
-
#initialize(options) ⇒ Convert
constructor
A new instance of Convert.
- #interlace_options ⇒ Object
- #new_format ⇒ Object
- #resize_thumbnail_options(size) ⇒ Object
- #rotate_options ⇒ Object
Constructor Details
#initialize(options) ⇒ Convert
Returns a new instance of Convert.
7 8 9 10 11 12 13 |
# File 'lib/imageproxy/convert.rb', line 7 def initialize() @options = if (!(.resize || .thumbnail || .rotate || .flip || .format || .quality || .)) raise "Missing action or illegal parameter value" end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/imageproxy/convert.rb', line 5 def @options end |
Instance Method Details
#convert_options ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/imageproxy/convert.rb', line 29 def = [] << "-resize #{(.resize)}" if .resize << "-thumbnail #{(.thumbnail)}" if .thumbnail << "-flop" if .flip == "horizontal" << "-flip" if .flip == "vertical" << if .rotate << "-colors 256" if .format == "png8" << "-quality #{.quality}" if .quality << if .progressive .join " " end |
#execute(user_agent = nil, timeout = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/imageproxy/convert.rb', line 15 def execute(user_agent=nil, timeout=nil) if . @overlay_file ||= Tempfile.new("imageproxy").tap(&:close) execute_command(curl ., :user_agent => user_agent, :timeout => timeout, :output => @overlay_file.path) execute_command curl(.source, :user_agent => user_agent, :timeout => timeout) + "| composite #{@overlay_file.path} - - | convert - #{} #{new_format}#{file.path}" file else execute_command %'#{curl .source, :user_agent => user_agent, :timeout => timeout} | convert - #{} #{new_format}#{file.path}' file end end |
#file ⇒ Object
80 81 82 |
# File 'lib/imageproxy/convert.rb', line 80 def file @tempfile ||= Tempfile.new("imageproxy").tap(&:close) end |
#interlace_options ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/imageproxy/convert.rb', line 65 def case .progressive when "true" "-interlace JPEG" when "false" "-interlace none" else "" end end |
#new_format ⇒ Object
76 77 78 |
# File 'lib/imageproxy/convert.rb', line 76 def new_format .format ? "#{.format}:" : "" end |
#resize_thumbnail_options(size) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/imageproxy/convert.rb', line 42 def (size) case .shape when "cut" "#{size}^ -gravity center -extent #{size}" when "preserve" size when "pad" background = .background ? %|"#{.background}"| : %|none -matte| "#{size} -background #{background} -gravity center -extent #{size}" else size end end |
#rotate_options ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/imageproxy/convert.rb', line 56 def if .rotate.to_f % 90 == 0 "-rotate #{.rotate}" else background = .background ? %|"#{.background}"| : %|none| "-background #{background} -matte -rotate #{.rotate}" end end |