Thanks Rob.
I am able to use this function to extract the EXIF width and height of an image, any ideas on how I can get the date and time using it?
local function getJpegInfo(fh, path) local function unpackMsbUint16(s) local c,d = s:byte(1,#s) local num = (c \* 256) + d return num end -- local function readMsbUint16(fh) return unpackMsbUint16(fh:read(2)) end -- local filePath = path or nil local theFile = nil -- if filePath == nil then theFile = system.pathForFile(fh, system.ResourceDirectory) else theFile = system.pathForFile(fh, path) end -- local fileHandle = assert(io.open(theFile, 'rb')) -- local self = {} -- --JPEG Markers local jpegSOI = string.char( 255 ) .. string.char( 216 ) local jpegAPP0 = string.char( 255 ) .. string.char( 224 ) local jpegSOF0 = string.char( 255 ) .. string.char( 192 ) local jpegSOF2 = string.char( 255 ) .. string.char( 194 ) -- local tempBytes -- repeat tempBytes = fileHandle:read(2) until ( ( tempBytes == jpegSOI ) or ( tempBytes == nil ) ) --assert( tempBytes~=nil, "SOI not found. Are you sure this is a JPEG file?" ) -- local APP0Marker = fileHandle:read(2) --assert( APP0Marker == jpegAPP0, "APP0 Marker not what's expected. Is this really a JPEG file?") -- local APP0Length = readMsbUint16(fileHandle) - 4 --we're 4 bytes into this thing already fileHandle:seek( "cur", APP0Length ) -- skipping ahead, but this is where the DPI is stored if you need it. -- local readHead -- repeat repeat tempBytes = fileHandle:read(2) until ( ( tempBytes == jpegSOF0 ) or ( tempBytes == jpegSOF2 ) or ( tempBytes == nil )) if tempBytes ~= nil then readHead = fileHandle:seek() if (tempBytes == jpegSOF0 or tempBytes == jpegSOF2) then print("Found SOF0:", tempBytes == jpegSOF0, "SOF2:", tempBytes == jpegSOF2) end end until tempBytes == nil if readHead then fileHandle:seek("set", readHead) fileHandle:read(3) -- length of frame self.bitDepth = readByte(fileHandle) -- bit depth self.height = readMsbUint16(fileHandle) -- image height self.width = readMsbUint16(fileHandle) -- image width print(readHead); end --close the file io.close(fileHandle) fileHandle = nil return self end
The credit for the function above goes to Toby2.
I’ve been playing around with the function and I’m able to also get the image DPI info, but not the date and time created. Any help will be appreciated.
Thanks guys!