Class: ImageVise::FitCrop
- Inherits:
-
Struct
- Object
- Struct
- ImageVise::FitCrop
- Defined in:
- lib/image_vise/operators/fit_crop.rb
Overview
Fits the image based on the smaller-side fit. This means that the image is going to be fit into the requested rectangle so that all of the pixels of the rectangle are filled. The gravity parameter defines the crop gravity (on corners, sides, or in the middle).
The corresponding Pipeline method is ‘fit_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!(magick_image) ⇒ Object
-
#initialize ⇒ FitCrop
constructor
A new instance of FitCrop.
Constructor Details
#initialize ⇒ FitCrop
Returns a new instance of FitCrop.
19 20 21 22 23 24 25 26 |
# File 'lib/image_vise/operators/fit_crop.rb', line 19 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
6 7 8 |
# File 'lib/image_vise/operators/fit_crop.rb', line 6 def gravity @gravity end |
#height ⇒ Object
Returns the value of attribute height
6 7 8 |
# File 'lib/image_vise/operators/fit_crop.rb', line 6 def height @height end |
#width ⇒ Object
Returns the value of attribute width
6 7 8 |
# File 'lib/image_vise/operators/fit_crop.rb', line 6 def width @width end |
Instance Method Details
#apply!(magick_image) ⇒ Object
28 29 30 |
# File 'lib/image_vise/operators/fit_crop.rb', line 28 def apply!(magick_image) magick_image.resize_to_fill! width, height, GRAVITY_PARAMS.fetch(gravity) end |