image resizer / thumbnail maker

Joined
Nov 20, 2010
Messages
37
Reaction score
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.
 
How about instead of copy and pasting code from the net, you expand on the code or at least explain to people exactly how it works...

(You're last couple of threads just posting code are useless).
 
i agree with xpwzard.. commenting it would help lots of members to understand the code..

to - xpwzard
it is simple calculation.. of height and width. shouldn't be hard to understand
 
And this is posted in the wrong section. Should be in JavaScript.
 
Back
Top