Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

getting dimentions of an uploaded image
  • Hello,

    I've came across the uploadify script a couple of days ago and it's great! Love the jQuery integration.

    I need however one more functionality - getting the dimentions (width and height) of the file (if the file is an image of course).

    I'm not a flash/flex developer and I'm not familiar with its API but i've googled some tutorials about getting the image dimentions with FileReference that uploadify uses and came up with a modification/extension of its actionscript code.

    First the fileSelectSingleHandler:

    function fileSelectSingleHandler(event:Event):void {
    // Check if the filename already exists in the queue
    fileItem = new Object();
    fileItem.file = FileReference(event.target);

    //new code
    fileItem.file.addEventListener(Event.COMPLETE, loadImageData);
    fileItem.file.load();
    //end of new code

    uploadify_clearFileUploadQueue(true);
    (...)
    }


    and two new methods:


    function loadImageData (evt:Event) : void {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getImageDims);
    loader.loadBytes(fileItem.file.data);
    }
    function getImageDims (evt:Event) : void {
    var sourceBMP:Bitmap = evt.currentTarget.loader.content as Bitmap;
    debug(sourceBMP.width + ', ' +sourceBMP.height);
    }

    which in theory, according to the tutorial/sample I've found should work:
    http://stackoverflow.com/questions/3439 ... and-height
    but... well... they don't.

    I've also tried to use "fileRefSingle" instead of "fileItem.file" but it' doesn't work either.

    As long as the .load(); method is called there seems to be en error in AS code, because - after selecting a file form a localhost - it is not added to the queue. If the .load() method is commented out all works fine - file is added to the queue, but of course I don't get the information I need.

    If anyone has some ideas how to get the dimentions of an uploaded image, please help.

    You can download the "myuploadify.fla" code from http://rapidshare.com/files/419864566/ulpoadify.zip and here http://rapidshare.com/files/419865505/ulpoadify.zip and after publishing and copying it to the example folder test it on the localhost.

    Regards,
    Jakub
  • I need this feature, too!
    I don't know how to develop AS3, hope this feature will be done!
  • you can do this by php script