Search code examples
titanium-mobileappcelerator

how to know the weight of a image of gallery?


 Ti.Media.openPhotoGallery({
    success:function(event) {                   
 attch = event.media;       
    },
    cancel:function(){
        console.log("error!");
    }
});

How can I know the weight of attch? and if is possible, the name of file in gallery.


Solution

  • As is mentioned in the documenation, method success will return an object that contain property media which is image/video in Blob format. If you want to know width of an image do this:

    Ti.Media.openPhotoGallery({
        success: function(event) {
            var image = event.media;
    
            console.log(image.width);
            console.log(image.size); // image size in bytes
        }
    });