5

I'm working on a website that uses lots of png24 files, for transparency.

I need to replace them with png8 files, as all the png fix style javascript workarounds for png24 cause IE6 to lock up randomly.

See this link to get an idea of the symptoms IE6 displays - http://blogs.cozi.com/tech/2008/03/transparent-pngs-can-deadlock-ie6.html

Does anybody know an easy way of targeting existing png24 files, to replace them with the png8s?

I'm using a OS X, and file browsers like Adobe bridge don't show this, nor can I find the info on the commandline, or the finder.

Help!

Dave DuPlantis
  • 6,378
  • 3
  • 26
  • 30
Chris Adams
  • 2,721
  • 5
  • 33
  • 45

7 Answers7

7

The file utility on OSX can tell you the colour depth in a PNG file, e.g:

% file foo.png 
foo.png: PNG image data, 1514 x 1514, 8-bit grayscale, non-interlaced
Alnitak
  • 334,560
  • 70
  • 407
  • 495
3

You actually CAN get alpha transparency in PNG-8's but it's super complicated. http://www.sitepoint.com/blogs/2007/09/18/png8-the-clear-winner/ http://www.personal.psu.edu/drs18/blogs/davidstong/2007/09/png8_alpha_transparency_from_f.html

It basically creates GIF like substance for IE6 and a real PNG with alpha transparency for better browsers. It's a more pleasant degradation path. Right now, I think you need Fireworks, but I am exploring other options.

2

To add to Alnitak’s answer, once you find all PNG24 you want to convert, you can batch them all with pngquant:

pngquant -v -f --ext .png 256 *.png

This converts all PNG files to PNG8 in place, overwriting them.

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
Kornel
  • 97,764
  • 37
  • 219
  • 309
  • Note that this converts 32-bit RGBA PNGs to 8-bit *or smaller* RGBA-palette PNGs. You can check the palette by running `pngcheck *.png`. If you absolutely need an 8-bit palette for some reason, see [this answer](https://stackoverflow.com/a/1468389/96656). – Mathias Bynens May 02 '17 at 11:46
  • @MathiasBynens AFAIK ImageMagick also does color-counting, so (apart from lower quality) it's not any different from pngquant when the image ends up needing only 4 or 2 bits. – Kornel May 02 '17 at 21:27
  • I had tested this before posting my previous comment. [This example image](https://tibiamaps.github.io/tibia-map-data/minimap-with-markers/Minimap_Color_32000_32000_7.png) goes from 32-bit RGB+alpha to an 8-bit palette using `convert`, while `pngquant` optimizes it to a 4-bit palette. (In 99% of all cases that would be desirable, however I have this weird use case where I need a palette that’s exactly 8-bit.) – Mathias Bynens May 03 '17 at 08:39
1

I think you might be asking the wrong question. PNG8s don't have the true-alpha you've been working hard to fix in IE6. If you replace the PNG24s with PNG8s you are no better off than replacing them with GIFs.

Maybe you could test an alternative replacement/fix script - there are some shockingly bad ones out there, maybe that's where the problem is?

Here's (and I say this tongue in cheek!) the right question.

Community
  • 1
  • 1
JoeBloggs
  • 1,467
  • 9
  • 8
  • 2
    PNG-8 actually supports storing an alpha value with every color on the palate, so, with he right program and optimization, they can look great. See one of the other answers. – Daniel Beardsley Jun 12 '10 at 07:46
  • 3
    PNG8 is not the same as GIF, as PNG8 can store semi-transparent pixels, where GIFs cannot. Photoshop does not have this ability (when trying to Save for Web), but it's very clear when you use Fireworks to export as PNG8. – RussellUresti Oct 24 '11 at 16:28
1

JoeBloggs is right, you're asking the wrong question.

I've never had IE6 break with a good pngfix script. You've either got a bad pngfix script, or a bad IE6 install.

PNG8 will ruin your nice transparencies and make it look like you're using GIFs.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
1

pngcheck, a command line tool, can dump the information you need. http://www.libpng.org/pub/png/apps/pngcheck.html

pngcheck.exe a.png
OK: a.png (1024x1024, 32-bit RGB+alpha, non-interlaced, 80.7%).

pngcheck.exe b.png
OK: b.png (1024x1024, 8-bit palette+trns, non-interlaced, 83.1%).
0

Perhaps imagemagick helps you out at converting png24 files to png8 files.

Cheery
  • 24,645
  • 16
  • 59
  • 83