Sym - 一个用 Java 实现的现代化社区平台 • 源码 • 注册

Pipe - 小而美的开源博客平台 • 体验 • 皮肤
Solo - 一个用 Java 实现的博客系统,为你或你的团队创建个博客吧! • 源码下载 
Wide - 一个基于 Web 的 Go 语言 IDE • 教程试用

web 图片优化


Author: Susie Sahim, Web Designer and Google Doodler

Recommended skills: Basic image manipulation

When you optimize every line of code for your website, don't forget about your static content - including images. Simple improvements can drastically decrease your download size, without diminishing the site's quality.


Here are a few tips to help you make your web graphics load faster

Crop out excess white space

Sometimes you have extra space or padding around graphics so that they don't touch accompanying text or web page elements. Instead, crop out that space and use CSS to create the padding around the graphic.

Use the best file format

For images containing flat illustrations or artwork, use the 8-bit PNG or GIF format and reduce the number of colors in the palette. Some image programs such as PhotoShop allow you to save the image for the web and fine-tune the image settings. By reducing the color palette from 256 to something like 32, you greatly reduce the size of the file. The less colors that the image has, the smaller the file size is going to be.

For very detailed and colorful artwork or for photographics, JPG and 24-bit PNG are typically used because they have a much larger color palette. While a 24-bit PNG results in superior image quality, this comes at the price of a larger file size. When you can, use JPG instead and adjust the quality setting so you can compress the image as much as possible within your desired tolerance for image quality.

To compare and contrast, here are the file sizes of the above graphic in various formats:

  • JPG, 60 quality - 32K
  • PNG-8, 256 colors - 37K
  • GIF, 256 colors - 42K
  • PNG-24 - 146K

Also note that JPG has an option called "Progressive" mode. This option adds multiple copies of the image at lower resolution to make the image appear quickly on the screen, while progressively improving in quality. But it also increases the overall size of the image.

PNG also has a similar feature called "Interlaced". You may want to turn this feature off so that the full image downloads quicker.

Because the 8-bit PNG and GIF formats have the potential to result in much smaller image files, try to keep this in mind when creating graphics and illustrations for your site. Try to keep the amount of colors to a minimum and use flat graphics instead of photographs. This way you can create images with palettes of 16 colors, keeping the file size extremely small and fast to download.