/ Published in: ActionScript 3
you'll need the xmp core lib from adobe for this to work.
http://www.adobe.com/devnet/xmp/library/eula.html
This is before real testing, so there WILL be errors!
http://www.adobe.com/devnet/xmp/library/eula.html
This is before real testing, so there WILL be errors!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private function init(event:Event):void { var ldr:Loader = new Loader(); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded); var s:String = "link/to/asset.jpg"; ldr.load(new URLRequest(s)); } private function imgLoaded(e:Event):void{ var info:LoaderInfo = e.target as LoaderInfo; var xmpXML:XML = getXMP(info.bytes); //trace(xmpXML); var meta:XMPMeta = new XMPMeta(xmpXML); } private function trim(s:String):String{ return s.replace( /^([\s|\t|\n]+)?(.*)([\s|\t|\n]+)?$/gm, "$2" ); } private function getXMP(ba:ByteArray):XML{ var LP:ByteArray = new ByteArray(); var PACKET:ByteArray = new ByteArray(); var l:int; ba.readBytes(LP, 2, 2); /* http://www.adobe.com/devnet/xmp.html read part 3: Storage in Files. that will explain the -2 -29 and other things you see here. */ l = LP.readInt() - 2 -29; ba.readBytes(PACKET, 33, l); var p:String = trim(""+PACKET); var i:int = p.search('<x:xmpmeta xmlns:x="adobe:ns:meta/"'); /* Delete all in front of the XMP XML */ p = p.substr(i); /* For some reason this left some rubbish in front, so I'll hardcode it out for now TODO clean up */ var ar:Array = p.split('<'); var s:String = ""; var q:int; var j:int = ar.length; for(q=1;q<j;q++){ s += '<'+ar[q]; } i = s.search('</x:xmpmeta>'); i += ('</x:xmpmeta>').length; s = s.slice(0,i); /* Delete all behind the XMP XML */ return XML(s); }