Class: ImageVise::Crop
- Inherits:
-
Struct
- Object
- Struct
- ImageVise::Crop
- Defined in:
- lib/image_vise/operators/crop.rb
Overview
Crops the image to the given dimensions with a given gravity. Gravities are shorthand versions of ImageMagick gravity parameters (see GRAVITY_PARAMS)
The corresponding Pipeline method is ‘crop`.
Constant Summary collapse
- GRAVITY_PARAMS =
{ 'nw' => Magick::NorthWestGravity, 'n' => Magick::NorthGravity, 'ne' => Magick::NorthEastGravity, 'w' => Magick::WestGravity, 'c' => Magick::CenterGravity, 'e' => Magick::EastGravity, 'sw' => Magick::SouthWestGravity, 's' => Magick::SouthGravity, 'se' => Magick::SouthEastGravity, }
Instance Attribute Summary collapse
-
#gravity ⇒ Object
Returns the value of attribute gravity.
-
#height ⇒ Object
Returns the value of attribute height.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #apply!(image) ⇒ Object
-
#initialize ⇒ Crop
constructor
A new instance of Crop.
Constructor Details
#initialize ⇒ Crop
Returns a new instance of Crop.
18 19 20 21 22 23 24 25 |
# File 'lib/image_vise/operators/crop.rb', line 18 def initialize(*) super self.width = width.to_i self.height = height.to_i raise ArgumentError, ":width must positive" unless width > 0 raise ArgumentError, ":height must positive" unless height > 0 raise ArgumentError, ":gravity must be within the permitted values" unless GRAVITY_PARAMS.key? gravity end |
Instance Attribute Details
#gravity ⇒ Object
Returns the value of attribute gravity
5 6 7 |
# File 'lib/image_vise/operators/crop.rb', line 5 def gravity @gravity end |
#height ⇒ Object
Returns the value of attribute height
5 6 7 |
# File 'lib/image_vise/operators/crop.rb', line 5 def height @height end |
#width ⇒ Object
Returns the value of attribute width
5 6 7 |
# File 'lib/image_vise/operators/crop.rb', line 5 def width @width end |
Instance Method Details
#apply!(image) ⇒ Object
27 28 29 |
# File 'lib/image_vise/operators/crop.rb', line 27 def apply!(image) image.crop!(GRAVITY_PARAMS.fetch(gravity), width, height, remove_padding_data_outside_window = true) end |