Class: Sequel::Plugins::Paperclip::Processors::Image::Geometry
- Inherits:
-
Object
- Object
- Sequel::Plugins::Paperclip::Processors::Image::Geometry
- Defined in:
- lib/sequel_paperclip/processors/image.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#modifiers ⇒ Object
Returns the value of attribute modifiers.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #aspect ⇒ Object
- #cropping(dst, ratio, scale) ⇒ Object
- #horizontal? ⇒ Boolean
-
#initialize(width = nil, height = nil, modifiers = nil) ⇒ Geometry
constructor
A new instance of Geometry.
- #larger ⇒ Object
- #scaling(dst, ratio) ⇒ Object
- #smaller ⇒ Object
- #square? ⇒ Boolean
- #to_s ⇒ Object
- #transform(dst, crop = false) ⇒ Object
- #vertical? ⇒ Boolean
Constructor Details
#initialize(width = nil, height = nil, modifiers = nil) ⇒ Geometry
Returns a new instance of Geometry.
64 65 66 67 68 |
# File 'lib/sequel_paperclip/processors/image.rb', line 64 def initialize(width = nil, height = nil, modifiers = nil) self.width = width.to_f self.height = height.to_f self.modifiers = modifiers end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
62 63 64 |
# File 'lib/sequel_paperclip/processors/image.rb', line 62 def height @height end |
#modifiers ⇒ Object
Returns the value of attribute modifiers.
62 63 64 |
# File 'lib/sequel_paperclip/processors/image.rb', line 62 def modifiers @modifiers end |
#width ⇒ Object
Returns the value of attribute width.
62 63 64 |
# File 'lib/sequel_paperclip/processors/image.rb', line 62 def width @width end |
Class Method Details
.from_file(file) ⇒ Object
70 71 72 73 74 |
# File 'lib/sequel_paperclip/processors/image.rb', line 70 def self.from_file(file) path = file.respond_to?(:path) ? file.path : file geometry = `identify -format %wx%h #{path}` from_s(geometry) end |
Instance Method Details
#aspect ⇒ Object
99 100 101 |
# File 'lib/sequel_paperclip/processors/image.rb', line 99 def aspect width/height end |
#cropping(dst, ratio, scale) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/sequel_paperclip/processors/image.rb', line 131 def cropping(dst, ratio, scale) if ratio.horizontal? || ratio.square? "%dx%d+%d+%d"%[dst.width, dst.height, 0, (self.height*scale-dst.height)/2] else "%dx%d+%d+%d"%[dst.width, dst.height, (self.width*scale-dst.width)/2, 0] end end |
#horizontal? ⇒ Boolean
91 92 93 |
# File 'lib/sequel_paperclip/processors/image.rb', line 91 def horizontal? height < width end |
#larger ⇒ Object
103 104 105 |
# File 'lib/sequel_paperclip/processors/image.rb', line 103 def larger [height, width].max end |
#scaling(dst, ratio) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/sequel_paperclip/processors/image.rb', line 123 def scaling(dst, ratio) if ratio.horizontal? || ratio.square? ["%dx"%dst.width, ratio.width] else ["x%d"%dst.height, ratio.height] end end |
#smaller ⇒ Object
107 108 109 |
# File 'lib/sequel_paperclip/processors/image.rb', line 107 def smaller [height, width].min end |
#square? ⇒ Boolean
87 88 89 |
# File 'lib/sequel_paperclip/processors/image.rb', line 87 def square? height == width end |
#to_s ⇒ Object
83 84 85 |
# File 'lib/sequel_paperclip/processors/image.rb', line 83 def to_s "%dx%d"%[self.width, self.height]+self.modifiers end |
#transform(dst, crop = false) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/sequel_paperclip/processors/image.rb', line 111 def transform(dst, crop = false) if crop ratio = Geometry.new(dst.width/self.width, dst.height/self.height) scale_geometry, scale = scaling(dst, ratio) crop_geometry = cropping(dst, ratio, scale) else scale_geometry = dst.to_s crop_geometry = nil end [scale_geometry, crop_geometry] end |
#vertical? ⇒ Boolean
95 96 97 |
# File 'lib/sequel_paperclip/processors/image.rb', line 95 def vertical? height > width end |