1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

image resizer / thumbnail maker

Discussion in 'HTML & JavaScript' started by s-c-0-r-p-i-a-n, Aug 28, 2011.

  1. s-c-0-r-p-i-a-n

    s-c-0-r-p-i-a-n BANNED BANNED

    Joined:
    Nov 20, 2010
    Messages:
    37
    Likes Received:
    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. 
     
  2. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    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).
     
  3. R3vproxy

    R3vproxy Newbie

    Joined:
    Sep 21, 2011
    Messages:
    17
    Likes Received:
    0
    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
     
  4. Crazy

    Crazy Jr. Executive VIP

    Joined:
    Jun 13, 2009
    Messages:
    640
    Likes Received:
    319
    Occupation:
    VB, C#, XHTML, CSS, PHP, MySQL, JavaScript, jQuery
    Location:
    Everywhere
    And this is posted in the wrong section. Should be in JavaScript.
     
  5. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    Done :D