Class: EXIFR::TIFF
- Inherits:
-
Object
- Object
- EXIFR::TIFF
- Includes:
- Enumerable
- Defined in:
- lib/exifr/tiff.rb
Overview
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:
-
TopLeftOrientation
-
TopRightOrientation
-
BottomRightOrientation
-
BottomLeftOrientation
-
LeftTopOrientation
-
RightTopOrientation
-
RightBottomOrientation
-
LeftBottomOrientation
These instances of Orientation have two methods:
-
to_i; return the original integer
-
transform_rmagick(image); transforms the given RMagick::Image to a viewable version
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
Defined Under Namespace
Classes: Data, Degrees, Field, GPS, IFD, Orientation
Constant Summary
- TAG_MAPPING =
:nodoc:
{}
- IFD_TAGS =
:nodoc:
[:image, :exif, :gps]
- ORIENTATIONS =
:nodoc:
[]
- ADAPTERS =
:nodoc:
Hash.new { proc { |v| v } }
- TAGS =
Names for all recognized TIFF fields.
([TAG_MAPPING.keys, TAG_MAPPING.values.map{|v|v.values}].flatten.uniq - IFD_TAGS).map{|v|v.to_s}
Instance Attribute Summary (collapse)
-
- (Object) jpeg_thumbnails
readonly
JPEG thumbnails.
Class Method Summary (collapse)
-
+ (Object) instance_methods(include_super = true)
:nodoc:.
- + (Object) instance_methods_without_tiff_extras
- + (Object) rational(n, d)
- + (Object) round(f, n)
Instance Method Summary (collapse)
-
- (Object) [](index)
Get index image.
-
- (Object) each
Yield for each image.
-
- (Object) gps
Get GPS location, altitude and image direction return nil when not available.
-
- (Object) height
Convenience method to access image height.
-
- (TIFF) initialize(file)
constructor
file is a filename or an IO object.
-
- (Object) inspect
:nodoc:.
-
- (Object) method_missing(method, *args)
Dispatch to first image.
-
- (Object) methods
:nodoc:.
-
- (Boolean) respond_to?(method)
:nodoc:.
-
- (Object) size
Number of images.
-
- (Object) to_hash
Get a hash presentation of the (first) image.
-
- (Object) width
Convenience method to access image width.
Constructor Details
- (TIFF) initialize(file)
file is a filename or an IO object. Hint: use StringIO when working with slurped data like blobs.
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/exifr/tiff.rb', line 341 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 |ifd| if ifd.jpeg_interchange_format && ifd.jpeg_interchange_format_length start, length = ifd.jpeg_interchange_format, ifd.jpeg_interchange_format_length data[start..(start + length)] end end.compact end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args)
Dispatch to first image.
374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/exifr/tiff.rb', line 374 def method_missing(method, *args) super unless args.empty? if @ifds.first.respond_to?(method) @ifds.first.send(method) elsif TAGS.include?(method.to_s) @ifds.first.to_hash[method] else super end end |
Instance Attribute Details
- (Object) jpeg_thumbnails (readonly)
JPEG thumbnails
43 44 45 |
# File 'lib/exifr/tiff.rb', line 43 def jpeg_thumbnails @jpeg_thumbnails end |
Class Method Details
+ (Object) instance_methods(include_super = true)
:nodoc:
398 399 400 |
# File 'lib/exifr/tiff.rb', line 398 def instance_methods(include_super = true) # :nodoc: (instance_methods_without_tiff_extras(include_super) + TAGS + IFD.instance_methods(false)).uniq end |
+ (Object) instance_methods_without_tiff_extras
397 |
# File 'lib/exifr/tiff.rb', line 397 alias instance_methods_without_tiff_extras instance_methods |
+ (Object) rational(n, d)
314 315 316 |
# File 'lib/exifr/tiff.rb', line 314 def self.rational(n, d) Rational.respond_to?(:reduce) ? Rational.reduce(n, d) : 1.quo(d) end |
+ (Object) round(f, n)
318 319 320 321 |
# File 'lib/exifr/tiff.rb', line 318 def self.round(f, n) q = (10 ** n) (f * q).round.to_f / q end |
Instance Method Details
- (Object) [](index)
Get index image.
369 370 371 |
# File 'lib/exifr/tiff.rb', line 369 def [](index) index.is_a?(Symbol) ? to_hash[index] : @ifds[index] end |
- (Object) each
Yield for each image.
364 365 366 |
# File 'lib/exifr/tiff.rb', line 364 def each @ifds.each { |ifd| yield ifd } end |
- (Object) gps
Get GPS location, altitude and image direction return nil when not available.
415 416 417 418 419 420 421 |
# File 'lib/exifr/tiff.rb', line 415 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 |
- (Object) height
Convenience method to access image height.
407 |
# File 'lib/exifr/tiff.rb', line 407 def height; @ifds.first.height; end |
- (Object) inspect
:nodoc:
423 424 425 |
# File 'lib/exifr/tiff.rb', line 423 def inspect # :nodoc: @ifds.inspect end |
- (Object) methods
:nodoc:
392 393 394 |
# File 'lib/exifr/tiff.rb', line 392 def methods # :nodoc: (super + TAGS + IFD.instance_methods(false)).uniq end |
- (Boolean) respond_to?(method)
:nodoc:
386 387 388 389 390 |
# File 'lib/exifr/tiff.rb', line 386 def respond_to?(method) # :nodoc: super || (defined?(@ifds) && @ifds && @ifds.first && @ifds.first.respond_to?(method)) || TAGS.include?(method.to_s) end |
- (Object) size
Number of images.
359 360 361 |
# File 'lib/exifr/tiff.rb', line 359 def size @ifds.size end |
- (Object) to_hash
Get a hash presentation of the (first) image.
410 |
# File 'lib/exifr/tiff.rb', line 410 def to_hash; @ifds.first.to_hash; end |
- (Object) width
Convenience method to access image width.
404 |
# File 'lib/exifr/tiff.rb', line 404 def width; @ifds.first.width; end |