Monday, August 25th, 2008
ImageInfo: reading image metadata (EXIF) with JavaScript
Jacob Seidelin finishes up his binary meme with a post on reading image metadata with JavaScript via a library that groks EXIF data.
It tries to detect the format of the image file and then reads the header and pulls out information about dimensions and color depth among other things. If the EXIF data library is included, it will also gather any EXIF tags from JPEG files.
- // URL of the image (must be on the same domain!)
- var file = "prettypicture.jpg";
- // define your own callback function
- function mycallback() {
- // either call the ImageInfo.getAllFields([file]) function which returns an object holding all the info
- alert(
- "All info about this file: " + ImageInfo.getAllFields(file).toSource()
- );
- // or call ImageInfo.getField([file], [field]) to get a specific field
- alert(
- "Format: " + ImageInfo.getField(file, "format") + ", dimensions : " + ImageInfo.getField(file, "width") + "x" + ImageInfo.getField(file, "height")
- );
- }
- // finally, load the data
- ImageInfo.loadInfo(file, mycallback);
ImageInfo, this library, was inspired by the App Engine app IMG2JSON.





If you drop in “flXHR” (http://flxhr.flensed.com/) you can do this binary file inspection cross-domain. :)
I thought this was done with a server side trick, but looking at teh code, it’s all javascript.
Very impressive!