Skip navigation.

exploreopera

| Help

Sign up | Help

Web Applications Blog

avatar

Optimizing PNG Graphics for Device

, , , , ,

One of the most recent image compression formats is PNG. The advanced features of PNG, such as high compression and 32-bit support makes it the format of choice for web applications. Opera supports PNG, both on desktop and device; we use this format for most of our graphics.

There are two things you should do to your graphics, when preparing them for device. The first is color reduction, the second is re-compressing. First color reduction.

Color reduction

Why would you want to reduce the amount of colors used? We want the maximum number of colors, right? Yeah! Unfortunately, most mobile devices do not support millions of colors; many of them support only a percentage of that. The key to making sure your images look good on device is reducing color depth, using dithering techniques. Corel’s Paint Shop Pro is the only graphics application I have tested which has a special “reduce to thousands-of-colors” feature.

If you don’t own a copy, you will have to posterize your images to the color depth of the target device. Then convert this image to indexed colors with an EXACT palette. Finally go back to your original 32 bits image and convert it to indexed colors using the PREVIOUS palette and the most appropriate dithering.

The important step is the dithering. Without that, on device, your images would look exactly as the posterized version.

Note that you might have to slice the image and repeat the process to obtain an EXACT palette.

The image might not look as nice on desktop as it used to, but it should at least look the same on desktop as on device. On to part two!

Image re-compression

Isn’t PNG compressed already? Of course it is, but don’t you think we can do better? In most cases we can. Most image editors add metadata in one form or another to PNG files. In most cases this is not needed, and chopping it away can save a lot of space. In one project my final zip file went from 300kb to measly 50kb by using these techniques.

To business. You might know about the PNG compressor "PNG Crush". It was the first I ever heard about, but it seems there are some others out there as well. The most famous are OptiPNG and PNGOut.

How do they compare? They're roughly the same. So which one you use is not important; the important thing is that you actually use one of these. Therefore; accessibility. Neil Turner has a very good article on adding PNG Crush to the right-click menu of PNG files (for Windows). No need to copy his blog post, go read it!

The problem with PNG Crush is that it can't replace the current file, meaning you will have to rename the result when you're done. That is why I prefer "PNGOut" instead, which can optimize-in place.

As a final mention for you Linux users, here is what our Virtuelvis uses:

(this is using first pngcrush, and then optipng)
Compress every png into directory 'out'
$ pngcrush -rem alla -brute -fix -d out *.png
recompress them
$ cd out 
$ optipng -zc1-9 -zm1-9 -zs0-3 -f0-5 *.png 
$ mv -f *.png ../

(mv -f can be replaced with your favorite windows file moving flavor)

After this optimizing session your PNG images should look better and be leaner than ever before! :up:

Opera Widget Competition - Sample CodeA word on Widget style...

Comments

avatar
Anonymous writes:

I make J2ME games for mobile phones. We have done several tests, and PNGOUT always comes out on top as the best PNG optimiser.

By anonymous user, # 28. April 2006, 08:36:02

avatar
I use PNGOut as well, but I have had cases where PNGOut can't do much, in that case using PNGCrush with "-fix" seems to get the file right ready for further PNGOut treatment. :wink:

By Helmers, # 28. April 2006, 09:01:40

avatar
pls how can i load or download a game into my nec e313 phone

By clembusky, # 28. April 2006, 14:23:01

avatar
Corel’s Paint Shop Pro is the only graphics application I have tested which has a special “reduce to thousands-of-colors” feature.
I use Irfanview's "decrease color depth" option and its PNGOUT plugin. I highly recommend it for Win.

By dantesoft, # 1. May 2006, 09:26:43

avatar
dantesoft: Thanks for the tip. Alas IrfanView's "decrease color depth" feature is a misnomer. It reduces the number of colors, not the color depth.

By p01, # 3. May 2006, 14:50:08

avatar
obviously I do not know much but what is the difference between decreasing colour depth and reducing number of colours?

By yadavankur, # 9. May 2006, 06:34:41

avatar
What we mean by decreasing color depth is going from 24bit -> 12bit (4096 colors) or 15bit (65536 colors).

Applications such as Photoshop and Irfanview typically only lets you choose between bit depts from 8bit and down, in addition to 24bit.

So you miss out on many of the colors you actually can display on a 12bit or 15bit device.

By Helmers, # 9. May 2006, 08:34:41

avatar
http://www.offerterimini.it writes:

Hello one question please ?

Does Opera displays correctly the Alfa channel, as in PNG the Alfa channel is give by 256 levels, instead of 1 color in GIF ??

Thank You

By anonymous user, # 18. August 2006, 21:48:14

avatar
http://www.offerterimini.it: Yes Opera does. On desktop, mobile and other devices.

By Helmers, # 19. August 2006, 05:40:13

avatar
For Photoshop users, the little gem of a plugin at: http://depthdither.graphest.com seems to do the trick.

By Demonstro, # 15. October 2007, 17:01:50

avatar
Notice that the pattern dithering is b0rked : the error is not spread correctly in Y.

Nifty tool though!

By p01, # 17. October 2007, 12:21:42

Write a comment

You must be logged in to write a comment. if you're not a registered member, please sign up.