views:

193

answers:

3

Is it possible to downsize an image in html while keeping proportions?

I know I can use height and width attribute of img tag, but I don't know the image size.

Please don't tell me to find out the image size on the server, or that the right way to do this is to generate thumbnails on the server side and that is saves bandwidth and improves page loading time.

I know what the ideal solution is. But I want quick and dirty...

+5  A: 

Quick and dirty: just set one of the attributes in img tag:

<img src="my.jpg" width="200" /> or <img src="my.jpg" height="200" />
Trick
+4  A: 

Yes. Just use height or width.

But quick and dirty is very dirty.

David Dorward
The link was proving that the quality of the browser resizing is very dependent of the browser: I tried it in Chrome, IE and Firefox. In IE and Firefox it was obvious that it used teh "fast" filter, but it was slightly better quality than the "fast" pre-processed image. In Chrome, it was actually very good quality on the browser-resized image. It was actually better than the high quality pre-processed image!
awe
I gave you +1 though because you are right in both the solution (use height **or** width), and that it is VERY dirty based on using more bandwidth than necessary.
awe
A: 

Remember also that you can give a percentage of the original width / height as value as well, for instance:

<img src="my.jpg" width="50%" />
Anax
This won't work in most cases - it will just set the image width to 50% of the width of the enclosing element.
Ben