I am developing a web application where use can upload pictures. I create thumbnails of various sizes. Lets say that one of the sizes is 240, 240 .
For this thumbnail when I render the image I want to put “height” and “width” attribute as it is recommended. However the image uploaded by user might be really tall and skinny. In that case the width will not be “240”.
What is the recommended height and width attribute for this case. Or should I not worry about height and weight attribute for thumbnails.
No, you should not put an incorrect
widthandheighton animgelement. What you should do, however, is output the correct size image when you’re creating the thumbnail. For example, instead of scaling an image down from500x200to240x96, create a new, transparent image that is240x240and place the scaled image (240x96) in the middle of the transparent image. Then, you can specify thewidthandheighton theimg, and not incorrectly stretch any images.