Class: Dimensions::ExifScanner

Inherits:
Scanner
  • Object
show all
Includes:
TiffScanning
Defined in:
lib/dimensions/exif_scanner.rb

Constant Summary collapse

ORIENTATION_TAG =
0x0112
ORIENTATIONS =
[
  :top_left,
  :top_right,
  :bottom_right,
  :bottom_left,
  :left_top,
  :right_top,
  :right_bottom,
  :left_bottom
]

Instance Attribute Summary collapse

Attributes inherited from Scanner

#pos

Instance Method Summary collapse

Methods included from TiffScanning

#read_integer_value, #scan_and_skip_to_offset, #scan_endianness, #scan_header, #scan_ifd, #scan_tag_mark

Methods inherited from Scanner

#advance, #big!, #little!, #raise_scan_error, #read, #read_char, #read_data, #read_long, #read_short, #skip_to

Constructor Details

#initialize(data) ⇒ ExifScanner

Returns a new instance of ExifScanner.



22
23
24
25
# File 'lib/dimensions/exif_scanner.rb', line 22

def initialize(data)
  @orientation = nil
  super
end

Instance Attribute Details

#orientationObject (readonly)

Returns the value of attribute orientation.



20
21
22
# File 'lib/dimensions/exif_scanner.rb', line 20

def orientation
  @orientation
end

Instance Method Details

#scanObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dimensions/exif_scanner.rb', line 27

def scan
  scan_header

  scan_ifd do |tag|
    if tag == ORIENTATION_TAG
      value = read_integer_value
      if valid_orientation?(value)
        @orientation = ORIENTATIONS[value - 1]
      end
    end
  end

  @orientation
end

#valid_orientation?(value) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/dimensions/exif_scanner.rb', line 42

def valid_orientation?(value)
  (1..ORIENTATIONS.length).include?(value)
end