Class: Riiif::Crop

Inherits:
Object
  • Object
show all
Defined in:
app/services/riiif/crop.rb

Overview

Represents a cropping operation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region, image_info) ⇒ Crop

Returns a new instance of Crop.

Parameters:

  • transformation (IIIF::Image::Region)

    the result the user requested

  • image_info


6
7
8
9
# File 'app/services/riiif/crop.rb', line 6

def initialize(region, image_info)
  @region = region
  @image_info = image_info
end

Instance Attribute Details

#image_infoObject (readonly)

Returns the value of attribute image_info.



11
12
13
# File 'app/services/riiif/crop.rb', line 11

def image_info
  @image_info
end

#regionObject (readonly)

Returns the value of attribute region.



11
12
13
# File 'app/services/riiif/crop.rb', line 11

def region
  @region
end

Instance Method Details

#to_imagemagickString

Returns a region for imagemagick to decode (appropriate for passing to the -crop parameter).

Returns:

  • (String)

    a region for imagemagick to decode (appropriate for passing to the -crop parameter)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/riiif/crop.rb', line 15

def to_imagemagick
  case region
  when IIIF::Image::Region::Full
    nil
  when IIIF::Image::Region::Absolute
    "#{region.width}x#{region.height}+#{region.offset_x}+#{region.offset_y}"
  when IIIF::Image::Region::Square
    imagemagick_square
  when IIIF::Image::Region::Percent
    imagemagick_percent
  else
    raise "Unknown region #{region.class}"
  end
end

#to_kakaduString

Returns a region for kakadu to decode (appropriate for passing to the -region parameter).

Returns:

  • (String)

    a region for kakadu to decode (appropriate for passing to the -region parameter)



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/riiif/crop.rb', line 32

def to_kakadu
  case region
  when IIIF::Image::Region::Full
    nil
  when IIIF::Image::Region::Absolute
    "\{#{decimal_offset_y(region.offset_y)},#{decimal_offset_x(region.offset_x)}\}," \
    "\{#{decimal_height(region.height)},#{decimal_width(region.width)}\}"
  when IIIF::Image::Region::Square
    kakadu_square
  when IIIF::Image::Region::Percent
    kakadu_percent
  else
    raise "Unknown region #{region.class}"
  end
end