Class: ImageVise::Crop

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

Instance Method Summary collapse

Constructor Details

#initializeCrop

Returns a new instance of Crop.

Raises:

  • (ArgumentError)


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

#gravityObject

Returns the value of attribute gravity

Returns:

  • (Object)

    the current value of gravity



5
6
7
# File 'lib/image_vise/operators/crop.rb', line 5

def gravity
  @gravity
end

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



5
6
7
# File 'lib/image_vise/operators/crop.rb', line 5

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

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