Generate "thumbnail" in html keeping aspect ratio

Is it possible to shrink an image in html while maintaining aspect ratio?

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

Please don't tell me to find out the size of the image on the server, or that the correct way to do it is to create thumbnails on the server side, and this saves bandwidth and improves page load times.

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

+2


source to share


3 answers


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



<img src="my.jpg" width="200" /> or <img src="my.jpg" height="200" />

      

+6


source


Yes. Just use height or .



But fast and dirty is very dirty .

+4


source


Remember also that you can also specify a percentage of the original width and height, for example:

<img src="my.jpg" width="50%" />

      

0


source







All Articles