class Exif::ExifParser

Public Class Methods

new(file_handler) click to toggle source

create a new object. fpath is String.

# File lib/exifparser.rb, line 102
def initialize(file_handler)
  @scanner = Exif::Scanner.new prepare_file(file_handler)
  @scanner.scan
  init_from_scanner
end

Public Instance Methods

[](tagname) click to toggle source

search the specified tag values. return value is object of classes defined under Exif::Tag module.

# File lib/exifparser.rb, line 150
def [](tagname)
  self.tag(tagname)
end
[]=(tag, value) click to toggle source

set the specified tag to the specified value. XXX NOT IMPLEMETED XXX

# File lib/exifparser.rb, line 158
def []=(tag, value)
  # not implemented
end
each(ifd=nil) { |tag| ... } click to toggle source

execute given block with block argument being every tags defined in all the IFDs contained in the image.

if argument ifd is specified, every tags defined in the specified IFD are passed to block.

return value is object of classes defined under Exif::Tag module.

allowable arguments are:

  • :IFD0

  • :IFD1

  • :Exif

  • :GPS

  • :Interoperability

  • :MakerNote

# File lib/exifparser.rb, line 223
def each(ifd=nil)
  if ifd
    @scanner.result[ifd].each{ |tag| yield tag }
  else
    [
      @IFD0,
      @IFD1,
      @Exif,
      @GPS,
      @Interoperability,
      @MakerNote
    ].flatten.each do |tag|
      yield tag
    end
  end
end
init_from_scanner() click to toggle source
# File lib/exifparser.rb, line 108
def init_from_scanner
  @IFD0 = @scanner.result[:IFD0]
  @IFD1 = @scanner.result[:IFD1]
  @Exif = @scanner.result[:Exif]
  @GPS  = @scanner.result[:GPS]
  @Interoperability = @scanner.result[:Interoperability]
  @MakerNote = @scanner.result[:MakerNote]
  @thumbnail = @scanner.result[:Thumbnail]
end
inspect() click to toggle source
# File lib/exifparser.rb, line 128
def inspect
  sprintf("#<%s filename=\"%s\" entries: IFD0(%d) IFD1(%d) Exif(%d) GPS(%d) Interoperability(%d) MakerNote(%d)>", self.class, @fpath, @IFD0.length, @IFD1.length, @Exif.length, @GPS.length, @Interoperability.length, @MakerNote.length)
end
marshal_dump() click to toggle source
# File lib/exifparser.rb, line 240
def marshal_dump
  {scanner: Marshal.dump(@scanner)}
end
marshal_load(marshaled) click to toggle source
# File lib/exifparser.rb, line 244
def marshal_load marshaled
  @scanner = Marshal.load marshaled[:scanner]
  init_from_scanner
end
orig_thumbnail(dest)
Alias for: thumbnail
prepare_file(handler) click to toggle source
# File lib/exifparser.rb, line 118
def prepare_file(handler)
  if handler.is_a? String
    @fpath = handler
    File.open(handler, "rb")
  elsif handler.is_a?(StringIO) || handler.is_a?(File)
    @fpath = 'dummy_file'
    handler
  end
end
tag(tagname, ifd=nil) click to toggle source

search tag on the specific IFD

# File lib/exifparser.rb, line 142
def tag(tagname, ifd=nil)
  search_tag(tagname, ifd)
end
tag?(tagid) click to toggle source

return true if specified tagid is defined or has some value.

# File lib/exifparser.rb, line 135
def tag?(tagid)
  search_tag(tagid) ? true : false
end
tags(ifd=nil) click to toggle source

return all the tags in the image.

if argument ifd is specified, every tags defined in the specified IFD are passed to block.

return value is object of classes defined under Exif::Tag module.

allowable arguments are:

  • :IFD0

  • :IFD1

  • :Exif

  • :GPS

  • :Interoperability

  • :MakerNote (if exist)

# File lib/exifparser.rb, line 192
def tags(ifd=nil)
  if ifd
    @scanner.result[ifd]
  else
    [
      @IFD0,
      @IFD1,
      @Exif,
      @GPS,
      @Interoperability,
      @MakerNote
    ].flatten
  end
end
thumbnail(dest) click to toggle source

extract the thumbnail image to dest. dest should respond to '<<' method.

# File lib/exifparser.rb, line 166
def thumbnail(dest)
  dest << @thumbnail
end
Also aliased as: orig_thumbnail
thumbnail_size() click to toggle source

return the size of the thumbnail image

# File lib/exifparser.rb, line 173
def thumbnail_size
  @thumbnail.size
end

Private Instance Methods

search_tag(tagID, ifd=nil) click to toggle source
# File lib/exifparser.rb, line 251
def search_tag(tagID, ifd=nil)
  if ifd
    @scanner.result(ifd).find do |tag|
      case tagID
      when Fixnum
        tag.tagID.hex == tagID
      when String
        tag.name == tagID
      end
    end
  else
    [
      @IFD0,
      @IFD1,
      @Exif,
      @GPS,
      @Interoperability,
      @MakerNote
    ].flatten.find do |tag|
      case tagID
      when Fixnum
        tag.tagID.hex == tagID
      when String
        tag.name == tagID
      end
    end
  end
end