Thursday 15 September 2011

javascript - How to Show Image Resolution to from its URL -



javascript - How to Show Image Resolution to from its URL -

i creating website share wallpapers can downloaded , used on users' desktops. not able find way show resolution visitors. yes, can write resolution myself, problem share many images , not possible me write resolution each image.

i able automatically create description want show image resolution.

is possible javascript accomplish this? no problem if shows result after image loads.

you can create img element in javascript without rendering on page:

var img = document.createelement('img'); img.src = "path_to_src";

now image created, can pull height , width using img.height , img.width, obtained 1 time image loads:

class="snippet-code-js lang-js prettyprint-override">var x = document.createelement('img'); x.src = "http://placehold.it/128x256"; x.onload = function() { var html = ""; html += "height = " + x.height + "px<br>"; html += "width = " + x.width + "px"; document.queryselector('p').innerhtml = html; } class="snippet-code-html lang-html prettyprint-override"><p> <!-- image height , width displayed here instead of below text. --> creating image , pulling height , width... </p>

javascript html image

No comments:

Post a Comment