How to find image data size using javascript? -


on webpage, once images have been downloaded , rendered, need determine image's file size (kb) within browser context (so display info on page, below image)

the easiest way head request returning content-length:

function filesize(img, func) {   var xhr = new xmlhttprequest();   xhr.open('head', img.src, true);   xhr.onreadystatechange = function() {     if(xhr.readystate == 4 && xhr.status == 200) {       func(xhr.getresponseheader('content-length'))      }   }   xhr.send() } 

usage

filesize(imgnode, function(size) {   // ... }) 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -