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.

JAVASCRIPT:

  1.  
  2.  
  3.  
  4. // URL of the image (must be on the same domain!)
  5. var file = “prettypicture.jpg”;
  6.  
  7. // define your own callback function
  8. function mycallback() {
  9.    // either call the ImageInfo.getAllFields([file]) function which returns an object holding all the info
  10.    alert(
  11.        “All info about this file: “ + ImageInfo.getAllFields(file).toSource()
  12.    );
  13.  
  14.    // or call ImageInfo.getField([file], [field]) to get a specific field
  15.    alert(
  16.        “Format: “ + ImageInfo.getField(file, “format”) + “, dimensions : “ + ImageInfo.getField(file, “width”) + “x” + ImageInfo.getField(file, “height”)
  17.    );
  18. }
  19.  
  20. // finally, load the data
  21. ImageInfo.loadInfo(file, mycallback);
  22.  

ImageInfo, this library, was inspired by the App Engine app IMG2JSON.

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/374206788/imageinfo-reading-image-metadata-exif-with-javascript

Comments are closed.



Site Navigation