When building out a web site, the graphics used play a major part. Pictures, gradients, textures and patterns are all elements of a site that need to be optimized to be placed into the code of a web site. It seems simple enough to just place an image into a site, but using the right file type can be tricky for a novice web developer. Here is a tutorial that will provide you with a little bit of insight into slicing up your designs and optimizing images for the web.
First, a little background info on what types of images can be used on the web. Three types of files can be used for display on a web site. The file types are JPEG (Joint Photographic Experts Group), GIF (Graphics Interchange Format) and PNG (Portable Network Graphics). These three file types have the ability to be compressed and optimized, allowing for smaller file sizes and faster site loading. Each format can be used for any image, but knowing when to use each can make a site load faster and look better.
JPEG is the most commonly used file for compression. JPEG allows for the amount of compression to be controlled, but sacrificing the image quality. The more compression selected will provide a smaller file, but will also lower the quality of an image. The trick is to compress an image just enough to not noticeably damage the quality of an image. I have found that using less than 60% compression will begin to pixellate an image. JPEG should be used for any photograph or image that can be classified as more complicated than a simple gradient.
GIF is a file type that does not lose image quality when compressed. But GIF files can only use a range of 256 colors, much less than JPEGs and can cause photographs to appear pixellated. GIF is preferred for sharp-edge line art with flat coloring, such as logos, or simple gradients. GIFs also allow for transparency, but with limitations. If a GIF has any curved or diagonal edges, a matte color will be present outside of those particular edges. The amount of matte color shown is minimal, and the color can be chosen. Choose a color that would best blend into the background in which the transparent GIF will be placed. GIFs can also be used for small animations, but I would not recommend using them unless you are designing a web site in the year 1998.
The final file type that can be used on a web site is the almighty PNG. PNGs completely retain maximum image quality after compression, also creating a larger file size. PNGs also provide transparency, but with a much wider range of options than GIFs. PNGs preserve the alpha transparency of an image. Here's an example to demonstrate: If a slice containing a graphic set at 50% opacity is compressed as a PNG, it will appear translucent, allowing for images or text placed behind the PNG to appear. Another example would be to use a PNG whenever an abnormally shaped object has a drop shadow. PNGs will preserve the translucency of a drop shadow.
PNGs are supported by most modern web browsers such as IE 8 and Firefox 3, but are not supported in older browsers like the decrepit IE 6 and below. There are ways to use PNGs in older browsers. Many developers use a PNG-fix, which is code that will allow PNGs to appear normally on older web browsers. Many developers frown on this method, claiming the PNG-fix code is "hacking" the code to show the image.
It might seem like a lot of information for such a simple task, but there are ways of viewing your images optimized before placing them into your code. In Photoshop (or ImageReady), create a slice in your design and select Save Optimized As from the File menu. This will take you to another screen. You will notice tabs at the top of the screen. Two of the options are Original and Optimized. Original shows the file as is with no compression. Optimized gives you a preview of the what the image sliced will look like after compression. Make sure the slice you created is selected and choose a file format on the right side. By selecting different file types for this one slice, you will see how each one affects the image quality. You can also view the file size after compression in the lower left corner of the Optimized view.
What it comes down to is personal preference. There isn't necessarily a right and a wrong way to optimize and compress your images. Most designers would rather not compress their designs at all, preserving the image quality at it's maximum, but do not understand that this would cause a site to load slowly. Again, finding the perfect balance between compression and quality is the key to creating a great looking and functioning web site.










