Class: ImageVise::FitCrop

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeFitCrop

Returns a new instance of FitCrop.

Raises:

  • (ArgumentError)


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

#gravityObject

Returns the value of attribute gravity

Returns:

  • (Object)

    the current value of gravity



6
7
8
# File 'lib/image_vise/operators/fit_crop.rb', line 6

def gravity
  @gravity
end

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



6
7
8
# File 'lib/image_vise/operators/fit_crop.rb', line 6

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of 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