Transparent .png files and image optimization
Posted by datonn on March 24th, 2010About 2-3 times every year, I have one of those “Duh! Why didn’t I think of that before?” moments. This week, my “Duh!” moment was in realizing that for a great-many .png images, removing the white background in them and replacing it with transparency would more than likely result in less pixel information needing to be stored for each image. And less pixel information needed to be stored would more than likely result in smaller overall file size.
I decided to put that theory to the test tonight. I picked three images from the mapformation.com website at-random that included a lot of white in them. The mapformation site uses a white background in its page template, so storing white background information in each of the .png files themselves would be unnecessary.
To perform this experiment, I used a combination of Adobe Fireworks and PNGSlim. In Fireworks, I used the Magic Wand Tool to remove a majority of the white from the image (all the background color). I then made the matte for the image transparent as well. When you save that .png out of Fireworks with alpha transparency, you’ll probably fall out of your chair, as the file size will INCREASE by roughly 15-30 times its original size. However, have no fear! Subsequently running the much larger .png out of Fireworks through PNGSlim will bring that file back down to a manageable size.

Unoptimized 750×97 pixel .png header graphic – 4,555 bytes

Optimized 750×97 pixel .png header graphic – 4,303 bytes

Unoptimized 201×155 pixel .png logo – 12,744 bytes

Optimized 201×155 pixel .png logo – 11,959 bytes

Unoptimized 251×37 pixel .png logo – 1,162 bytes

Optimized 251×37 pixel .png logo – 1,071 bytes
18.0 KB of imagery was reduced to 16.9 KB in cumulative size, an improvement of 6.2 percent. Not bad at all, considering those images had already been turned into “flying tin cans” at an earlier date by Yours Truly.
Replacing an unnecessary background with transparency is probably something many of you reading this have already been doing for years! However, in case you’re like me, I thought I’d share my “Duh!” moment and potentially save you a little time. Enjoy!
