Class: Riiif::Crop
- Inherits:
-
Object
- Object
- Riiif::Crop
- Defined in:
- app/services/riiif/crop.rb
Overview
Represents a cropping operation
Instance Attribute Summary collapse
-
#image_info ⇒ Object
readonly
Returns the value of attribute image_info.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
Instance Method Summary collapse
-
#initialize(region, image_info) ⇒ Crop
constructor
A new instance of Crop.
-
#to_imagemagick ⇒ String
A region for imagemagick to decode (appropriate for passing to the -crop parameter).
-
#to_kakadu ⇒ String
A region for kakadu to decode (appropriate for passing to the -region parameter).
Constructor Details
#initialize(region, image_info) ⇒ Crop
Returns a new instance of Crop.
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_info ⇒ Object (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 |
#region ⇒ Object (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_imagemagick ⇒ String
Returns 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_kakadu ⇒ String
Returns 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 |