Well, today I surely teared myself apart! I spent about 10 hours to get myself femiliar with how the three most popular image formats, jpg, png and gif work and how we can use the flash AS3 ByteArray class to extract this information!
I must confess that I still am very unclear about a lot of different things in byteArray class but the least I managed was to find and combine some classes and finally managed to output the kind of information I needed.
Before anything I must thank to Antti, who wrote the beautiful class of how we can read and use binary data of jpg file. you may read his artical here.
The problem with Antti class was that his class supported jpeg format only and didn't extract all the other information I needed and actually was too bugy for my needs!
So, I had to do some more searches here and there and I found this other artical here which did made me happy by how it extracted image info and it supported all the three formats. but the problem with this latter class was that it actually extracted all the data just after it loaded the whole file entirely! which in practice makes it useless, at least for my purpose.
So, I have the two classes, one tells me how to search for the information I need the other one tells me how to kill the loading process as soon as I found out the information I was looking for!
ok, good, finally what I did was to combine the two classes together and build a new class which you can download here:
http://emstris.com/sample/AS3/byteArray/ImageInfoExtractor.as
(simply put it in your class files in this location: com\myflashlab\classes\tools\imageEncoders)
and using this new class I put together, you can find out a lot of information about images before they are downloaded entirely
actually this information gets extracted in just a second! maybe less than a second.
you will be able to use the above class like this:
looks nice and clean, right? yeah, this will be absolutly useful in big and complex projects.
I have also a sample online, check below and see how the class has extracted the information out of the big image, about 800 kb, in just a second! and kills the connection right after that.
I hope you enjoy the class. just one thing, I would really love to be able to find out the header binary information of a swf file also. if anyone managed to update this class so that it also supports .swf input, I'd be more than happy to have it also
Thanks,
Hadi

My Flash Lab
May 17th, 2009 11:23 pm
Very nice work. Thanks for sharing
May 17th, 2009 11:37 pm
Thanks Antii, but still working on .swf binary data…
May 19th, 2009 6:40 pm
Very nice combination of the two ideas! For more binary metadata resources (including .swf) check out the metaphile project at google code created by Ben Stucki: http://code.google.com/p/metaphile/
May 19th, 2009 7:03 pm
hmm, but the download page there says “This project currently has no downloads.”
is it something temporary?
May 23rd, 2009 9:06 pm
You’ll have to get it from the svn server http://metaphile.googlecode.com/svn/trunk/ preferably using an svn client.
June 7th, 2009 4:35 pm
Devon, frankly, I didn’t know how to use svn, but now, thanks to you, I had to find more about that…
June 10th, 2009 1:06 am
Nice work! I’m working on a project where I need to find out the image orientation from the exif metadata and then rotate the image to its correct position accordingly. Any ideas on how one might extend your class to include that functionality?
June 10th, 2009 1:59 am
@Aaron, well, the main part is to know what information you are looking for in the binary loaded data… I think searching the web for the exif info would help to know what is to be found for your special purposes and then you may do anything with it…
I am also trying to find a way to extract the inner thumbnail being available in jpeg files so I can load an image thumbnail without having to manually create a thumbnail!!! Working with binary data is really fun and a lot of new things are possible.
If you found some new interesting things, let us know about it also here
August 31st, 2010 8:02 pm
Hey I’m trying to do something similar but with auto-generated ZIP files.
How were you able to read the filesize prior to the loading? Are you making two consecutive calls? (One to determine the size, another one to get the actual file(s))
To further understand what I’m trying to achieve, please see this thread on Ultrashock:
http://www.ultrashock.com/forums/data-communication/as3-urlstream-php-zip-on-demand-get-bytestotal-filename-126242.html
I’m curious as to how you did it. Everywhere I’m reading, it seems a standalone / browser SWF object cannot get httpResponseStatus events, but in AIR it can.
Any help would be great! Thanks
September 1st, 2010 1:45 pm
seems like you have already got the answer, but anyhow, in my sample, I actually try loading the file with URLLoader and check if we have enough binary info to read the header of the file… when we do, I kill the loading process which is usually less than 5k.