[JavaScript] get Image true size

2009.06.16 23:49

// get Image true size
var img_true_size = function(image){
var w = image.width ,
h = image.height ;

if ( "naturalWidth" in image ) { // for Firefox, Safari, Chrome
w = image.naturalWidth;
h = image.naturalHeight;

} else if ( typeof image.runtimeStyle !== 'undefined' ) { // for IE
var run = image.runtimeStyle;
var mem = { w: run.width, h: run.height }; // keep runtimeStyle
run.width = "auto";
run.height = "auto";
w = image.width;
h = image.height;
run.width = mem.w;
run.height = mem.h;

} else { // for Opera
var mem = { w: image.width, h: image.height }; // keep original style
image.removeAttribute("width");
image.removeAttribute("height");
w = image.width;
h = image.height;
image.width = mem.w;
image.height = mem.h;
}

return {width:w, height:h};
}

via. http://d.hatena.ne.jp/uupaa/20090602/1243933843

posted by wokamoto1973

違反を報告する