3

Recently, I was working on an image in Photoshop and wanted to save it for web usage. I wanted to know whether there is a good size to go with for the modern design standards when it comes to websites. I am a little hesitant to save it as a 1920 X 1080 simply because it is on the higher end and then use CSS to move it around as a background.

I am also not sure that using the more common 960px as the width will really serve my needs when the viewport size of a browser goes beyond that with all the new resolutions out there.

Furthermore, I am a little concerned with the size of the image and loss of quality as we get into higher resolutions considering that if I start small, I am left with little growing room and then having to deal with a diluted image as the size of the viewport goes up.

Any recommendations or links that talk about this? I am trying to build a site using responsive design and I have seem some JavaScript utilities that let you resize images but I am more concerned with the size of the image to start with and moving from there.

Thanks for any help or suggestions here.

2 Answers 2

1

This is what I personally do:

Save two versions of the images in two different sizes.

  • One for 1x resolution devices (most of them)
  • One for 2x resolutions devices (like iPad retina). The dimensions of this image are 200% the dimensions of the previous one.

Then, instead of using the src attribute of the <img> tag, I use CSS to

  • Apply the image as a background
  • Set the width and high of the image to the dimensions of the 1x resolution one.
  • Set background-dimension to contain. This makes sure the image is stretched to cover the whole img tag. Will make sense when you read the next comments.

I set the src attribute of the img to a transparent gif.

Finally, using media queries, I target the high res devices and change the version of the image to the 2x version. Since the background-dimension is still set to contains, the 2x image is shrunk to the dimensions of the img tag. The dimension stays correct but the device has the extra pixels available that it needs to show the image without blurriness.

Example: Suppose you want to show the image of a dog at 120px x 50px but want the image to appear sharp on iPad4 (which has 2x resolution). I save the image with those exact dimensions (dog-r1.jpg) and then to 200% of those dimensions: 240px x 100px (dog-r1.jpg).

This is my HTML

<img id="imgDog" src="transparent.gif" alt="" />

And this is my CSS

#imgDog{
   width:120px;
   height:50px;
   background-image:url(dog-r1.jpg);
   background-size:contain;
}

//iPad 4 media query
@media screen and (device-width: 768px) and (device-height: 1024px) and (-webkit-device-pixel-ratio: 2) {
   background-image:url(dog-r2.jpg); 
} 

When the page is viewed with an iPad 4, the background image will be replaced with dog-r2.jpg, but will still be displayed at 120x50px. Since the iPad 4 had double the resolution, the image will display at its sharpest best.

This is a very simplistic example, since one does not want to target only one device (iPad 4) but all devices that have more than resolution 1x as a bulk. If you are interested in media queries, there is plenty of resources and discussions online about the topic.

This is a great resource for media queries quick lookups: http://nmsdvid.com/snippets/

1
  • Thanks for the link and I am upvoting this because it talks about using resolution containment versus images that are different. Although, I have nothing against hosting up multiple images for various viewport sizes, I think its an unnecessary step that I am trying to avoid so that I only host maybe three or four images and use their original resolutions to match the viewport sizes letting the responsive design do the rest via CSS. Commented Apr 17, 2013 at 5:47
1

you should save image for different resolution and use them by css media query

and include image according to scree size

/* Smartphones (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 320px) 
and (max-device-width : 480px) {
/* Styles */
}

/* Smartphones (landscape) ----------- */
@media only screen 
and (min-width : 321px) {
/* Styles */
}

/* Smartphones (portrait) ----------- */
@media only screen 
and (max-width : 320px) {
/* Styles */
}

/* iPads (portrait and landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) {
/* Styles */
}

/* iPads (landscape) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : landscape) {
/* Styles */
}

/* iPads (portrait) ----------- */
@media only screen 
and (min-device-width : 768px) 
and (max-device-width : 1024px) 
and (orientation : portrait) {
/* Styles */
}

/* Desktops and laptops ----------- */
@media only screen 
and (min-width : 1224px) {
/* Styles */
}

/* Large screens ----------- */
@media only screen 
and (min-width : 1824px) {
/* Styles */
}

/* iPhone 4 ----------- */
@media
only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
/* Styles */
}
1
  • I like that approach and for the most part, it does solve the issue of taking care of different screen resolutions based on the size of the viewport but now I have to make images in those contained resolutions to solve the issue of a growing space where the image may not necessarily fall into a specific image height/width. Commented Apr 17, 2013 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.