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) ⇒ Object



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

def self.convert(img, rotate)
  rotation = Rotation.new(img).get(rotate)
  if rotation
    img.rotate(rotation) {|crop| yield crop}
  else
    yield img
  end
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)
  if rotate.nil? or rotate.eql? '0'
    return nil
  end
  raise BadRequest.new("bad rotate #{rotate}") unless rotate =~ /^-?\d+$/
  # negate offset because IIIF spec counts clockwise, FreeImage counterclockwise
  r = (rotate.to_i * -1) % 360
  r = r + 360 if r < 0
  raise BadRequest.new("bad rotate #{rotate}") unless RIGHT_ANGLES.include? r
  return r > 0 ? r : nil
end