Javascript dynamic image resizing


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function ResizeImage(image, maxwidth, maxheight)
  2. {
  3. if (image.className == "Thumbnail")
  4. {
  5. w = image.width;
  6. h = image.height;
  7.  
  8. if( w == 0 || h == 0 )
  9. {
  10. image.width = maxwidth;
  11. image.height = maxheight;
  12. }
  13. else if (w > h)
  14. {
  15. if (w > maxwidth) image.width = maxwidth;
  16. }
  17. else
  18. {
  19. if (h > maxheight) image.height = maxheight;
  20. }
  21.  
  22. image.className = "ScaledThumbnail";
  23. }
  24. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.