/usr/share/tdiary/exifparser.rb is in tdiary-contrib 3.2.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | #
#
#= exifparser.rb - Exif tag parser written in pure ruby
#
#Author:: Ryuchi Tamura (r-tam@fsinet.or.jp)
#Copyright:: Copyright (C) 2002 Ryuichi Tamura.
#
# $Id: exifparser.rb,v 1.1.1.1 2002/12/16 07:59:00 tam Exp $
#
#== INTRODUCTION
#
#There are 2 classes you work with. ExifParser class is
#the Exif tag parser that parses all tags defined EXIF-2.2 standard,
#and many of extension tags uniquely defined by some digital equipment
#manufacturers. Currently, part of tags defined by FujiFilm, and
#Olympus is supported. After initialized with the path to image file
#of EXIF format, ExifParser will provides which tags are available in
#the image, and how you work with them.
#
#Tags availble from ExifParser is objects defined under Exif::Tag module,
#with its name being the class name. For example if you get "Make" tag
#from ExifParser, it is Exif::Tag::DateTime object. Inspecting it looks
#following:
#
# #<Exif::Tag::TIFF::Make ID=0x010f, IFD="IFD0" Name="Make", Format="Ascii" Value="FUJIFILM">
#
#here, ID is Tag ID defined in EXIF-2.2 standard, IFD is the name of
#Image File Directory, Name is String representation of tag ID, Format is
#string that shows how the data is formatted, and Value is the value of
#the tag. This is retrieved by Exif::Tag::Make#value.
#
#Another example. If you want to know whether flash was fired when the image
#was generated, ExifParser returns Exif::Tag::Flash object:
#
# tag = exif['Flash']
# p tag
# => #<Exif::Tag::Exif::Flash ID=0x9209, IFD="Exif" Name="Flash", Format="Unsigned short" Value="1">
# p tag.value
# => 1
#
#It may happen that diffrent IFDs have the same tag name. In this case,
#use Exif#tag(tagname, IFD)
#
#The value of the tag above, 1, is not clearly understood
#(supposed to be 'true', though). Exif::Tag::Flash#to_s will provides
#more human-readable form as String.
#
# tag.to_s #=> "Flash fired."
#
#many of these sentences are cited from Exif-2.2 standard.
#
#== USAGE
# require 'exifparser'
#
# exif = ExifParser.new("fujifilm.jpg")
#
# 1. get a tag value by its name('Make') or its ID (0x010f)
# exif['Make'] #=> 'FUJIFILM'
# exif[0x010f] #=> 'FUJIFILM'
#
# if the specified tag is not found, nil is returned.
#
# 2. to see the image has the value of specified tag
# exif.tag?('DateTime') #=> true
# exif.tag?('CameraID') #=> false
#
# 3. get all the tags contained in the image.
#
# exif.tags
#
# or, if you want to know all the tags defined in specific IFD,
#
# exif.tags(:IFD0) # get all the tags defined in IFD0
#
# you can traverse each tag and work on it.
#
# exif.each do |tag|
# p tag.to_s
# end
#
# # each tag in IFD0
# exif.each(:IFD0) do |ifd0_tag|
# p ifd0_tag.to_s
# end
#
# 4. extract thumbnail
#
# File.open("thumb.jpg") do |dest|
# exif.thumbnail dest
# end
#
# dest object must respond to '<<'.
#
require 'exifparser/scan'
module Exif
class Parser
#
# create a new object. fpath is String.
#
def initialize(fpath)
@fpath = fpath
@scanner = nil
File.open(fpath, "rb") do |f|
@scanner = Exif::Scanner.new(f)
@scanner.scan
end
@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
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
#
# return true if specified tagid is defined or has some value.
#
def tag?(tagid)
search_tag(tagid) ? true : false
end
#
# search tag on the specific IFD
#
def tag(tagname, ifd=nil)
search_tag(tagname, ifd)
end
#
# search the specified tag values. return value is object of
# classes defined under Exif::Tag module.
#
def [](tagname)
self.tag(tagname)
end
#
# set the specified tag to the specified value.
# XXX NOT IMPLEMETED XXX
#
def []=(tag, value)
# not implemented
end
#
# extract the thumbnail image to dest. dest should respond to
# '<<' method.
#
def thumbnail(dest)
dest << @thumbnail
end
#
# return the size of the thumbnail image
#
def thumbnail_size
@thumbnail.size
end
#
# 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)
def tags(ifd=nil)
if ifd
@scanner.result[ifd]
else
[
@IFD0,
@IFD1,
@Exif,
@GPS,
@Interoperability,
@MakerNote
].flatten
end
end
#
# 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
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
private
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
end # module Parser
end # module Exif
ExifParser = Exif::Parser
|