Class: Imogen::Iiif::Rotation

Inherits:
Transform show all
Defined in:
lib/imogen/iiif/rotation.rb

Constant Summary collapse

RIGHT_ANGLES =
[0,90,180,270]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Transform

#initialize, #max, #min

Constructor Details

This class inherits a constructor from Imogen::Iiif::Transform

Class Method Details

.convert(img, rotate) {|img| ... } ⇒ Object

Yields:

  • (img)


17
18
19
20
21
22
23
24
# File 'lib/imogen/iiif/rotation.rb', line 17

def self.convert(img, rotate)
  angle, flip = Rotation.new(img).get(rotate)
  # IIIF spec applies horizontal flip ("mirrored by reflection on the vertical axis") before rotation
  img = img.fliphor if flip
  # No need to rotate if angle is zero
  img = img.rot("d#{angle}") unless angle.zero?
  yield img
end

Instance Method Details

#get(rotate) ⇒ Object

Raises:



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/imogen/iiif/rotation.rb', line 5

def get(rotate)
  return [0, false] if rotate.nil?
  original_rotate_value = rotate
  rotate = rotate.to_s
  raise BadRequest.new("bad rotate #{original_rotate_value}") unless rotate =~ /^!?-?\d+$/
  flip = rotate.to_s.start_with?('!')
  # libvips and IIIF spec counts clockwise
  angle = rotate.sub(/^!/, '').to_i % 360
  raise BadRequest.new("bad rotate #{original_rotate_value}") unless RIGHT_ANGLES.include?(angle)
  return angle, flip
end