Are bloated images slowing down your web site and causing you lost business? Images comprise over 50% of the average web page so putting them on a diet is essential to improving web performance. One of the best ways to optimize GIFs and PNGs is to minimize the "bit-depth" or the number of colors within your images.
For palette-based formats like GIF and PNG, file size is directly related to the size of the color palette, or the number of colors in the image. As the number of colors in an image crosses a power of two, the file size jumps. A 33-color image must use a six-bit palette, while a 32-color image can use a 5-bit palette. Smaller palettes mean smaller codes (representing pixel patterns), which makes for smaller files. So minimizing the number of colors in index-color images like GIFs and PNGs will minimize file size.
The compression schemes used in GIFs (LZW) and PNGs (Deflate) are dictionary-based encoding algorithms. Dictionary based compression algorithms substitute shorter codes for longer patterns of strings within the data stream. Pixel patterns (substrings) in the data stream found in the dictionary are replaced with a single code. If a substring is not found in the dictionary, a new code is created and added to the dictionary. Compression is achieved when smaller codes are substituted for longer patterns of data.
The code size is based on the number of bits per pixel, and depends on the maximum length code within your dictionary. Thus the smaller your bit-depth, the smaller the codes representing your pixel pattern strings, and the smaller the file.
Choosing the right format for your images is the first step in optimizing web graphics. At lower bit-depths, banding can appear in smooth-toned images. Try quantizing your image to different palettes to minimize banding.
PNG Compression
PNG uses the deflate compression algorithm which is a newer, more efficient cousin of LZW. Deflate is designed to be free of patent problems. Deflate is a combination of the LZ77 algorithm found in zip programs like WinZIP and gzip, and Huffman coding. Deflate typically compresses files 20 to 30 percent smaller than LZW, which is the difference you'll find between gzip and compress. PNGs use a similar substitution technique, but are generally 5 to 25 percent smaller than GIFs, although there are exceptions. In addition to horizontal "scan-line" pattern substitution PNGs sometimes substitute for vertical patterns. PNG can also truncate color palettes. In general, the smaller the color palette, the smaller the overal file size.
Conclusion
To minimize the file size of palette-based image formats like GIF and PNG, minimize their bit-depth, or number of colors. Each time you pass a power of two, file size jumps higher. By minimizing the number of colors, and maximizing the flat-color areas you will create smaller, more efficient images destined for the Web.
Further Reading:
LZW Data Compression
http://www.dogma.net/markn/articles/lzw/lzw.htm
Mark Nelson breaks down the LZW compression algorithm for Dr. Dobb's Journal of October 1989.
Multimedia: Use Lossy Compression for Smaller GIFs and PNGs http://www.dogma.net/markn/articles/lzw/lzw.htm
Lossy compression lets you squeeze more bytes out of your GIFs and PNGs. Lossy compression increases identical pixel patterns to improve compression in indexed-color images.
Multimedia: Use Weighted Optimization
http://www.dogma.net/markn/articles/lzw/lzw.htm
Weighted optimization or regional compression applies different degrees of compression to different areas of your image. By varying the quality within images you can improve file size.
Optimizing Web Graphics
http://www.dogma.net/markn/articles/lzw/lzw.htm
Chapter summary from Speed Up Your Site, shows how to correct, optimize, and compress images for minimum file size and maximum quality.
PNG Home Site
http://www.dogma.net/markn/articles/lzw/lzw.htm
Greg Roelofs site devoted to all things PNG.
About The Author
Article by Andy King, author of the popular new book titled "Speed Up Your Site ? Web Site Optimization". Visit Andy King's web site to learn the best Web Site Optimization practices for higher traffic and speed guaranteed. http://www.dogma.net/markn/articles/lzw/lzw.htm
A PHP Redirect automatically transfers a web user from one... Read More
How popular is online shopping? And is there room for... Read More
Like any area of business your website needs some effort... Read More
Before you jump into spending coutnless hours on designing and... Read More
Do you make your website just to entertain yourself or... Read More
Thousands of people are now making a living online and... Read More
When visitors add your web site to their Favorites or... Read More
After having decided to start a business, the next thing... Read More
1. Upload robots.txt file in to your root directory and... Read More
2 Golden Rules for an Engaging Website35% of visitors fail... Read More
Any new website competing on the internet, needs to take... Read More
Directory Generator, a product from Armand Morin and Marc Quarles,... Read More
The cost of setting up a web site is dirt... Read More
SiteSpinnerSiteSpinner is a user-friendly web site development tool that includes... Read More
Is Your Web Site an Expense or an Investment?Why don't... Read More
Globalize Your WebsiteThe Internet has unlocked a wide array of... Read More
Although CSS layouts have been around for years, they haven't... Read More
Your web site will be your window to the world.... Read More
Installment 1Developing State-enabled Applications With PHPWhen a user is browsing... Read More
There was a time not long ago when setting up... Read More
When you started reading this sentence you assumed lo acabar?a... Read More
Webmasters deal with a myriad of complex design challenges every... Read More
Everyday thousands of new businesses make the leap and take... Read More
Right after the thought, "I need a website," people usually... Read More
Why do some sites succeed while the vast majority of... Read More
Like wine cars get more attractive to collectors as years... Read More
Huge Mistake #1: Creating a Website with Flash -- Did... Read More
The internet is a sea of knowledge. Getting your information... Read More
A while ago one of my clients approached me and... Read More
If you're an up and coming graphic/web designer just out... Read More
Recently, a friend asked "What's the deal with those DIY... Read More
In the late 1990's three San Francisco based web developers... Read More
We've all seen those messages on some websites warning not... Read More
After years of working with entrepreneurs who developed their first... Read More
Failure, just like success, is measured differently by each and... Read More
#5 User Satisfaction: Learn what your visitors and site users... Read More
Are you aware that 90% of the websites on the... Read More
That's right. According to a recent study by Nielsen/NetRatings, Amazon.com... Read More
If you have some experience in web site design and... Read More
August 8 2005, Macromedia announced a release of Studio 8.... Read More
When used to describe a web site, the term "sticky"... Read More
1) A marketing necessityI still hear it said from time... Read More
You have seen those web pages where they have the... Read More
Think up a name and check if yourname.com is available.... Read More
In this day and age most businesses consider having their... Read More
Is Your Web Site an Expense or an Investment?Why don't... Read More
Most web sites are more like stage sets than real... Read More
With all of the factors involved in designing and building... Read More
For years now I've been looking to start my own... Read More
In my previous life.....Actually, my previous JOB life, I was... Read More
Web Development |