Hi,
I found this script here by Jacob Seidelin that uses ajax to retrieve image meta data.
I modified the script to only return a few values. Clicking on the link in the test page will show 3 values in an alert window.
My question is how do I isolate each one of those values into it's own variable? ex (x=0, y=1024, z= 683).
Also I would like to understnad how the code below works. I removed a lot of code from the orginal metadata script to try to simplify it in hopes I could understand it better but I'm not really sure how the script access and returns values from a file. For example, I'm trying to understand how the script finds the PixelXDimension value(0xA002).
Test Page
http://www.inspiredvisuals.com/test/test/test.html
Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <script type="text/javascript" src="binaryajax.js"></script> <script type="text/javascript" src="imageinfo.js"></script> <script> function GetExif() { function callback() { exif= files["image.jpg"]["exif"] var str = ""; for (var a in exif) {str += exif[a] + "\r\n";} alert(str); } readFileData("image.jpg", callback); } </script> </head> <body> <a href="#" onclick = "GetExif()">Get Image Dimensions Using EXIF Data</a> </body> </html>
Code:/* * ImageInfo 0.1.2 - A JavaScript library for reading image metadata. * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/ * MIT License [http://www.nihilogic.dk/licenses/mit-license.txt] */ var ImageInfo = {}; ImageInfo.useRange = true; ImageInfo.range = 632; var EXIF = {}; var iOffset = 2; var files = []; function readFileData(url, callback) { BinaryAjax( url, function(http) { var tags = findEXIFinJPEG(http.binaryResponse); var mime = http.getResponseHeader("Content-Type"); tags["mimeType"] = mime; tags["byteSize"] = http.fileSize; files[url] = tags; callback(); }, null, ImageInfo.useRange ? [0, ImageInfo.range] : null ) } function findEXIFinJPEG(oFile) { var exif = {}; EXIF.readFromBinaryFile = function(oFile) { while (iOffset < oFile.getLength()) { var iMarker = oFile.getByteAt(iOffset+1, true); if (iMarker == 225) {return readEXIFData(oFile)} else {iOffset += 2 + oFile.getShortAt(iOffset+2, true)} } } exif = EXIF.readFromBinaryFile(oFile); return {exif : exif} } function readTags(oFile, iDirStart, oStrings) { var oTags = {}; for (var i=0;i<oFile.getShortAt(iDirStart);i++) { var strTag = oStrings[oFile.getShortAt(iDirStart + i*12 + 2)]; oTags[strTag] = oFile.getLongAt(iDirStart + i*12 + 10); } return oTags; } function readEXIFData(oFile) { var oTags = readTags(oFile, (iOffset+18), (EXIF.TiffTags = {0x8769 : "ExifIFDPointer"})); var oEXIFTags = readTags(oFile, (iOffset+10 + oTags.ExifIFDPointer), (EXIF.Tags = {0xA002 : "PixelXDimension",0xA003 : "PixelYDimension"})); return oEXIFTags; }
Thanks.



Reply With Quote
Bookmarks