tags:

views:

146

answers:

4

If I have a logo image, and I want to use it on another page where I require it to be a smaller size, it is my instinct to create a new image, resized with a graphics editor. However, I am hearing that it is better for the user if I instead refer to the original image and resize it with the browser by changing the height and width in the image tag.

So I ask the crowd, what is the best practice here?

Thank you for your time,

-- Henry

A: 

It's fine to resize images with CSS or the height and width tags. The only thing you want to be careful of is making really large images small because it obviously doesn't decrease the download size.

Doing this would work best when you're effectively caching your images so it doesn't get downloaded a second time. Then you will be getting a tangible benefit from doing so. I usually just append the last modified time of the image to the URL, eg:

<img src="/images/log.png?1233454568">

and then set the Expires header to a year from now. If the image changes, the mtime changes and it will force the browser to reload it.

That's suggested for images, Javascript and CSS files.

cletus
+1  A: 

If the browser resizes the image for you by using height/width tag, you might end with a lesser quality image, really depends on the image type (like photo vs. simple graphics), so try it out in some common browsers. But resizing the image in a graphics editor is the only way to ensure a high-quality resize operation.

Chris O
+1  A: 

My default response would be "Resize it in a graphics application", but it depends on how you're using it.

When you leave image resizing to the browser, the original (full-size) image has to be downloaded before the browser can display it at a smaller scale. This means that you use more bandwidth and your webpage takes longer to load. However, if you mainly use the larger image throughout your site, then it will be faster to always use this image, since the browser can cache it.

If you're concerned about image quality, you would get better results and would have more control over the downsampling process using a dedicated graphics application to resize the image.

Steve Harrison
-1 Sorry but that's patently untrue. If you use the same image URL on both pages and cache it effectively you'll only download it once. Your method will *always* download it twice.
cletus
@cletus: True, but it *does* slow down loading time. If the user only visits pages where the small version of the image is used, they are forced to download the larger image. Of course, if the large image is used most, then, as you say, it will be faster to use the same image.
Steve Harrison
I hear you in regards to the size (and you'll see I noted that in my answer) but in this case the OP called it a logo. That's something *highly* likely to have been seen by the user already and also most likely not that large.
cletus
+1  A: 

Create the smaller image in a graphics editor, for several reasons:

  1. If users have not already cached the larger image, they will be downloading the larger file unnecessarily.

  2. Resizing the image client-side results in some unpredictable scaling quality.

  3. Doing it in HTML is ill-advised anyway, for presentational issues (such as element sizes) you should do it via CSS.

Alex Burr