PDA

View Full Version : Resizing only large images, not small ones.


johnstires
11-15-2006, 12:37 AM
I have an html question about resizing an image. How do you resize an image only if it's too big.

For instance if I have an image that is 500px wide and I want to down size it to 450px wide I can write something like this:

<embed src="$filename"


width=450>
</embed>

However if I have an image come in at 200px I do not want it resized to 450px.

How would I write it so that only images over 450px would get resized but images under 450px would stay the same.


Thanks in advanced!

CyberAlien
11-15-2006, 03:03 PM
<img src="blah" onload="if(this.width > 450) {this.width=450;}" />

johnstires
11-15-2006, 08:17 PM
This works alot better, Thanks! Is there a way to write it so that I do not see the image resize when the page loads? The embed tag I used did not do that, but the image one I use does.


<div align="center">

<img src="$filename" onload="if(this.width > 450) {this.width=450;}" />


</img>

</div>

CyberAlien
11-15-2006, 08:24 PM
Try this:

<img src="$filename" onload="if(this.width > 450) {this.width=450;} this.style='';" style="display:none;" />

johnstires
11-17-2006, 08:23 PM
The image doesn't load at all with that code.

CyberAlien
11-17-2006, 08:30 PM
Maybe try to put it in div with size 1x1 and overflow:hidden and when image loads resize that div to image size?

johnstires
11-18-2006, 01:48 AM
I'm sorry, my coding skills aren't that good. I'm not really sure what you are describing.