s-c-0-r-p-i-a-n
BANNED
- Nov 20, 2010
- 37
- 2
Code:
<script>
function resizeimage(picture, maxwidth, maxheight, actualwidth, actualheight)
{
if(document.getElementById(picture))
{
picture = document.getElementById(picture);//to call the function with id or "this" method
}
var picwidth, picheight, widfactor, hifactor;
picwidth = actualwidth;
picheight = actualheight;
widfactor = Math.round(actualwidth/maxwidth);
hifactor = Math.round(actualheight/maxheight);
if(widfactor>0 && hifactor>0)
{
picture.style.width = Math.round(picwidth/widfactor) + "px";//picture.style.width = "10px";
picture.style.height = Math.round(picheight/hifactor) + "px";//"10px";
}
}
</script>
<img src="mypic.jpg" onload="resizeimage(this, '60', '60', this.width, this.height)"/>
function called with "this"
<hr>
<img src="myimg.jpg" id="img" onload="resizeimage('img', '60', '60', this.width, this.height)"/>
function called with id.