Class: EXIFR::TIFF
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, Field, IFD, Orientation
Constant Summary collapse
- 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
-
#jpeg_thumbnails ⇒ Object
readonly
JPEG thumbnails.
Class Method Summary collapse
-
.instance_methods(include_super = true) ⇒ Object
:nodoc:.
- .instance_methods_without_tiff_extras ⇒ Object
Instance Method Summary collapse
-
#[](index) ⇒ Object
Get
index
image. -
#each ⇒ Object
Yield for each image.
-
#height ⇒ Object
Convenience method to access image height.
-
#initialize(file) ⇒ TIFF
constructor
file
is a filename or an IO object. -
#inspect ⇒ Object
:nodoc:.
-
#method_missing(method, *args) ⇒ Object
Dispatch to first image.
-
#methods ⇒ Object
:nodoc:.
-
#respond_to?(method) ⇒ Boolean
:nodoc:.
-
#size ⇒ Object
Number of images.
-
#to_hash ⇒ Object
Get a hash presentation of the (first) image.
-
#width ⇒ Object
Convenience method to access image width.
Constructor Details
#initialize(file) ⇒ TIFF
file
is a filename or an IO object.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/tiff.rb', line 306 def initialize(file) data = Data.new(file) case data[0..1] when 'II'; data.endianess = 'v' when 'MM'; data.endianess = 'n' else; raise 'no II or MM marker found' end @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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Dispatch to first image.
345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/tiff.rb', line 345 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
#jpeg_thumbnails ⇒ Object (readonly)
JPEG thumbnails
41 42 43 |
# File 'lib/tiff.rb', line 41 def jpeg_thumbnails @jpeg_thumbnails end |
Class Method Details
.instance_methods(include_super = true) ⇒ Object
:nodoc:
369 370 371 |
# File 'lib/tiff.rb', line 369 def instance_methods(include_super = true) # :nodoc: (instance_methods_without_tiff_extras(include_super) + TAGS + IFD.instance_methods(false)).uniq end |
.instance_methods_without_tiff_extras ⇒ Object
368 |
# File 'lib/tiff.rb', line 368 alias instance_methods_without_tiff_extras instance_methods |
Instance Method Details
#[](index) ⇒ Object
Get index
image.
340 341 342 |
# File 'lib/tiff.rb', line 340 def [](index) index.is_a?(Symbol) ? to_hash[index] : @ifds[index] end |
#each ⇒ Object
Yield for each image.
335 336 337 |
# File 'lib/tiff.rb', line 335 def each @ifds.each { |ifd| yield ifd } end |
#height ⇒ Object
Convenience method to access image height.
378 |
# File 'lib/tiff.rb', line 378 def height; @ifds.first.height; end |
#inspect ⇒ Object
:nodoc:
383 384 385 |
# File 'lib/tiff.rb', line 383 def inspect # :nodoc: @ifds.inspect end |
#methods ⇒ Object
:nodoc:
363 364 365 |
# File 'lib/tiff.rb', line 363 def methods # :nodoc: (super + TAGS + IFD.instance_methods(false)).uniq end |
#respond_to?(method) ⇒ Boolean
:nodoc:
357 358 359 360 361 |
# File 'lib/tiff.rb', line 357 def respond_to?(method) # :nodoc: super || (@ifds && @ifds.first && @ifds.first.respond_to?(method)) || TAGS.include?(method.to_s) end |
#size ⇒ Object
Number of images.
330 331 332 |
# File 'lib/tiff.rb', line 330 def size @ifds.size end |
#to_hash ⇒ Object
Get a hash presentation of the (first) image.
381 |
# File 'lib/tiff.rb', line 381 def to_hash; @ifds.first.to_hash; end |
#width ⇒ Object
Convenience method to access image width.
375 |
# File 'lib/tiff.rb', line 375 def width; @ifds.first.width; end |