Jump to content

[SOLVED] Image Resizer


mcmuney

Recommended Posts

Can anyone provide a javascript that will resize any image that exists on a page that exceeds a given number to a different size? For example, lets say that an image exists on the page which has a width of 1200. On the script, my criteria for the width is 600. In this example, since the image being displayed at 1200, which exceeds the 600 maximum, it'll display the image at 600.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/87286-solved-image-resizer/
Share on other sites

try this (but you will have to give each of your pictures a unique id - you can do this dynamically or statically):

 


<script language="javascript">
function checkSize(wide,what)
{
if (wide > 600) {
document.getElementById(what).style.width="600";
}
}
</script>

<img id="pic1" src="picture1.jpg" onload="checkSize(this.width,this.id)">

Link to comment
https://forums.phpfreaks.com/topic/87286-solved-image-resizer/#findComment-446501
Share on other sites

actually try this instead; this version will maintain the current height and only change the width:

 


<script language="javascript">
function checkSize(wide,high,what)
{
if (wide > 600) {
document.getElementById(what).style.width="600";
document.getElementById(what).style.height=""+high+"";
}
}
</script>

<img id="pic1" src="test.jpg" onload="checkSize(this.width,this.height,this.id)">

Link to comment
https://forums.phpfreaks.com/topic/87286-solved-image-resizer/#findComment-446503
Share on other sites

its work in FFv2.0.0.4 and IE6 (I did not test in IE7, don't have it on this computer - but it should work the same way); because I tested in both. the second version should not distort the image; I made it, so it would only resize the width of the image. the first version I made resized the width with javascript and the browser was automatically resizing the height due to the width size. this was because the image (as you stated) would not have a standard width/height property.

Link to comment
https://forums.phpfreaks.com/topic/87286-solved-image-resizer/#findComment-446524
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.