1

I saw that you can embed meta-data into images very much like you can in mp3s, here.

Can someone point me to a tutorial of how to embed and read this sort of information w/ photoshop and flex together? I really wouldn't know where to start... Tried googling but I'm not sure I have the right keywords down.

Thanks!

jml
  • 1,745
  • 6
  • 29
  • 55

4 Answers4

2

I've written a small snippet on the matter. this snippet is far from being proper tested, and is most definite not written in a clear and coherent way. But for now it seems to work. I'll update as I work on it.

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);
}

Originally from http://snipplr.com/view/51037/xmp-metadata-from-jpg/

Gabe
  • 84,912
  • 12
  • 139
  • 238
Pjetr
  • 1,372
  • 10
  • 20
1

Well AS3 don't have a built-in class to read jpg header.

BUT, if you are loading the image using URLLoader you can use the ByteArray to read if manually.

You can find the spec here: http://www.obrador.com/essentialjpeg/HeaderInfo.htm

If you need some tutorial of using Bytearray you can start from here: How to convert bytearray to image or image to bytearray ?

or here: http://digitalmedia.oreilly.com/pub/a/oreilly/digitalmedia/helpcenter/flex3cookbook/chapter8.html?page=7

The principle is the same -read the bytes, convert them to readable data using the spec above and use it.

Good luck!

Community
  • 1
  • 1
David Salzer
  • 872
  • 1
  • 7
  • 24
1

Photoshop (CS4+ I think) can also add XMP headers (XML style) which will be easier to parse than bytes but it contains different information.

http://code.google.com/p/exif-as3/

Here is a class that should do the job. It is non-commercial only but there is another option.

www.ultrashock.com/forums/server-side/extracting-metadata-from-photos-86065.html

Here is a php script that will do it that could be ported to as3 - it might be easier than creating one from scratch. If you did want php to read the info I would use the built in exif functions :)

pedro_sland
  • 4,765
  • 1
  • 16
  • 16
  • Cool library. I will definitely be checking this out... Yeah, I had heard about the built in EXIF functions of php- I get the feeling that this would ultimately be more clean and quick to load. – jml Jan 04 '10 at 22:33
0

Yes, entirely possible. ByteArray is your friend.

You may want to give a read to this: http://www.anttikupila.com/flash/getting-jpg-dimensions-with-as3-without-loading-the-entire-file/

This may also be of use, but I'd rather go with the first option: http://download.macromedia.com/pub/developer/xmp/sdk/XMPLibrary-v1.0.zip

Senekis
  • 111
  • 8