This is a Lua binding for libexif. Compatible with Lua 5.1 or later.
$ luarocks make LIBEXIF_DIR=/usr/local
Or, manually with Makefile:
$ make LUA=/usr/local LIBEXIF=/usr LDFLAGS=-shared
$ cp exif.so /path/to/module/dir/
The exif
module:
exif = require "exif"
Loads the module and set it to a variable. Note that the call torequire
does not set a global variable.exif.new()
Allocates a newdata
and returns it.exif.loadfile(filename)
Loads the file specified byfilename
. Returns adata
.exif.loadbuffer(buffer)
Loads the buffer given bybuffer
. Returns adata
.
Data types:
data
--- the entire EXIF data found in an image.mnotedata = data.mnotedata
Returns the MakerNote data.data:fix()
data:loadbuffer(buffer)
content = data:ifd(ifd)
ifd
is one of"0"
,"1"
,"EXIF"
,"GPS"
,"Interoperability"
. Returns an IFD.data:ifds()
Returns a integer-indexed table that contains all IFDs.
content
--- all EXIF tags found in a single IFD.content:fix()
content.ifd
Returns one of"0"
,"1"
,"EXIF"
,"GPS"
,"Interoperability"
.entry = content:entry(tag)
Returns an EXIF tag.content:entries()
Returns a table that contains all EXIF tags.content.parent
entry
--- one EXIF tagentry:fix()
entry.tag
Tag name as a string.entry.value
Returns a localized textual representation of the value.entry.components
entry.format
Returns a textual representation of the data type.entry.rawdata
entry.parent
Returns the content object to whichentry
belongs.entry.data
Same asentry[1]
entry[n]
(n
is an integer between1
andentry.components
)tostring(entry)
Same asentry.value
.
mnotedata
--- all data found in MakerNote tag.#mnotedata
mnotedata[n]
n
is an integer between1
and#mnotedata
.
rational
--- a rational number, possibly returned byentry.data
orentry[n]
rational.numerator
The numerator as an integer.rational.denominator
The denominator as an integer.rational.value
The ratio as a Lua number.tostring(rational)
Same asrational.numerator .. "/" .. rational.denominator
.
local exif = require "exif"
local data = exif.loadfile("mypicture.jpg") -- Load the EXIF data from "mypicture.jpg"
print(data:ifd("0"):entry("DateTime")) --> "2014:10:25 12:55:22"
local ExposureTime = data:ifd("EXIF"):entry("ExposureTime")
print(ExposureTime) --> "1/125 sec."
print(ExposureTime.format) --> "Rational"
print(ExposureTime.data) --> "1/125"
print(ExposureTime.data.value) --> "0.008"
Note that requiring "exif" module doesn't set a global variable with the module name.
You can assign the module (result of require
) to a local variable, as in the example above.