Class: ImageVise::Crop

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