class EXIFR::TIFF

TIFF decoder

Date properties

The properties :date_time, :date_time_original, :date_time_digitized coerced into Time objects.

Orientation

The property :orientation describes the subject rotated and/or mirrored in relation to the camera. It is translated to one of the following instances:

These instances of Orientation have two methods:

Examples

EXIFR::TIFF.new('DSC_0218.TIF').width           # => 3008
EXIFR::TIFF.new('DSC_0218.TIF')[1].width        # => 160
EXIFR::TIFF.new('DSC_0218.TIF').model           # => "NIKON D1X"
EXIFR::TIFF.new('DSC_0218.TIF').date_time       # => Tue May 23 19:15:32 +0200 2006
EXIFR::TIFF.new('DSC_0218.TIF').exposure_time   # => Rational(1, 100)
EXIFR::TIFF.new('DSC_0218.TIF').orientation     # => EXIFR::TIFF::Orientation

Constants

GPS
TAGS

Names for all recognized TIFF fields.

Attributes

mktime_proc[RW]

Callable to create a Time object. Defaults to proc{|*a|Time.local(*a)}.

jpeg_thumbnails[R]

JPEG thumbnails

Public Class Methods

new(file) click to toggle source

file is a filename or an IO object. Hint: use StringIO when working with slurped data like blobs.

# File lib/exifr/tiff.rb, line 372
def initialize(file)
  Data.open(file) do |data|
    @ifds = [IFD.new(data)]
    while ifd = @ifds.last.next
      break if @ifds.find{|i| i.offset == ifd.offset}
      @ifds << ifd
    end

    @jpeg_thumbnails = @ifds.map do |v|
      if v.jpeg_interchange_format && v.jpeg_interchange_format_length
        start, length = v.jpeg_interchange_format, v.jpeg_interchange_format_length
        data[start..(start + length)]
      end
    end.compact
  end
end
rational(n, d) click to toggle source
# File lib/exifr/tiff.rb, line 339
def self.rational(n, d)
  if d == 0
    n.to_f / d.to_f
  elsif Rational.respond_to?(:reduce)
    Rational.reduce(n, d)
  else
    n.quo(d)
  end
end
round(f, n) click to toggle source
# File lib/exifr/tiff.rb, line 349
def self.round(f, n)
  q = (10 ** n)
  (f * q).round.to_f / q
end

Public Instance Methods

[](index) click to toggle source

Get index image.

# File lib/exifr/tiff.rb, line 400
def [](index)
  index.is_a?(Symbol) ? to_hash[index] : @ifds[index]
end
each() { |ifd| ... } click to toggle source

Yield for each image.

# File lib/exifr/tiff.rb, line 395
def each
  @ifds.each { |ifd| yield ifd }
end
encode_with(coder) click to toggle source
# File lib/exifr/tiff.rb, line 427
def encode_with(coder)
  coder["ifds"] = @ifds
end
gps() click to toggle source

Get GPS location, altitude and image direction return nil when not available.

# File lib/exifr/tiff.rb, line 454
def gps
  return nil unless gps_latitude && gps_longitude
  GPS.new(gps_latitude.to_f * (gps_latitude_ref == 'S' ? -1 : 1),
          gps_longitude.to_f * (gps_longitude_ref == 'W' ? -1 : 1),
          gps_altitude && (gps_altitude.to_f * (gps_altitude_ref == "\1" ? -1 : 1)),
          gps_img_direction && gps_img_direction.to_f)
end
height() click to toggle source

Convenience method to access image height.

# File lib/exifr/tiff.rb, line 446
def height; @ifds.first.height; end
method_missing(method, *args) click to toggle source

Dispatch to first image.

Calls superclass method
# File lib/exifr/tiff.rb, line 405
def method_missing(method, *args)
  super unless args.empty?

  if @ifds.first.respond_to?(method)
    @ifds.first.send(method)
  elsif TAGS.include?(method)
    @ifds.first.to_hash[method]
  else
    super
  end
end
size() click to toggle source

Number of images.

# File lib/exifr/tiff.rb, line 390
def size
  @ifds.size
end
to_hash() click to toggle source

Get a hash presentation of the (first) image.

# File lib/exifr/tiff.rb, line 449
def to_hash; @ifds.first.to_hash; end
to_yaml_properties() click to toggle source
# File lib/exifr/tiff.rb, line 431
def to_yaml_properties
  ['@ifds']
end
width() click to toggle source

Convenience method to access image width.

# File lib/exifr/tiff.rb, line 443
def width; @ifds.first.width; end