The Sea King Posted February 17, 2008 Share Posted February 17, 2008 How do I javascript a code that resizes images to 640 pixels in height and 480 in width if the image is over 640px and 480px? Link to comment Share on other sites More sharing options...
jhecht Posted February 17, 2008 Share Posted February 17, 2008 Don't believe javascript resizes images... you can use the height/width attribute of an image tag to have the image displayed smaller, but you need a server side language to resize the image if i'm not mistaken. Link to comment Share on other sites More sharing options...
Synook Posted February 17, 2008 Share Posted February 17, 2008 You can "resize" an image using JS to modify its height and width, but it will look weird as there will not be interpolation, as it gets smaller pixels will just be sacrificed, making the image look jagged. You can use PHP's GD image functions to smoothly resize an image. Link to comment Share on other sites More sharing options...
The Sea King Posted February 18, 2008 Author Share Posted February 18, 2008 Don't believe javascript resizes images... you can use the height/width attribute of an image tag to have the image displayed smaller, but you need a server side language to resize the image if i'm not mistaken.I just want it to be displayed smaller... Link to comment Share on other sites More sharing options...
Synook Posted February 19, 2008 Share Posted February 19, 2008 Something like this will do then (images you want to resize give a class of small) function setsizes() { images = document.getElementsByTagName('img'); for (i = 0; i < images.length; i++) { img = images[i]; if (img.className == "small") { if (img.height > 640 || img.width > 480) { if (img.height > 3 * (img.width / 4)) img.style.height = "480px"; else img.style.width = "640px"; } } }} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.