Class Fleximage::Operator::Crop
In: lib/fleximage/operator/crop.rb
Parent: Operator::Base

Crops the image without doing any resizing first. The operation crops from the :from coordinate, and returns an image of size :size down and right from there.

  image.crop(options = {})

Use the following keys in the options hash:

  • from: coorinates for the upper left corner of resulting image.
  • size: The size of the resulting image, going down and to the right of the :from coordinate.

Both options are required.

Example:

  @photo.operate do |image|
    image.crop(
      :from => '100x50',
      :size => '500x350'
    )
  end

Methods

operate  

Public Instance methods

[Source]

    # File lib/fleximage/operator/crop.rb, line 25
25:       def operate(options = {})
26:         options = options.symbolize_keys
27: 
28:         # required integer keys
29:         [:from, :size].each do |key|
30:           raise ArgumentError, ":#{key} must be included in crop options" unless options[key]
31:           options[key] = size_to_xy(options[key])
32:         end
33: 
34:         # width and height must not be zero
35:         options[:size].each do |dimension|
36:           raise ArgumentError, ":size must not be zero for X or Y" if dimension.zero?
37:         end
38: 
39:         # crop
40:         @image.crop!(options[:from][0], options[:from][1], options[:size][0], options[:size][1], true)
41:       end

[Validate]