save PNMImage to a png8?

Is it possible to have PNMImage.write() write out a png8 file instead of a png32 file?


frameim = PNMImage()

I want test.png to be a very small file, and png8 would be just fine (there is not a lot of colors in my scene).

If I have to, I can use a different image saving library (i.e. PIL or ImageMagick), but the problem is that converting from PNMImage to another image format has so far proven to be really slow (so far I’ve only seen ways to copy over 1 pixel at a time, instead of a nice big memcpy-type conversion).


Hmm, looking at Panda’s PNM writer code, it looks like it will automatically generate a pnm8 image if it determines there are fewer than 256 colors in your image.

So one answer is, make sure that your scene really doesn’t have that many colors. You might need to, for instance, turn off lighting and antialiasing, which may tend to add a lot of gradient colors.


I checked and my source image only has 32 colors in it… is it possible the PNM only allows png8 if there is no translucency (i.e. it only allows alpha values of 0 and 255)?

Many png writers and readers don’t correctly implement png8 with translucency, even though it is supported in the format.

No, I think that should work. It appears to work for me.

Try setting:

notify-level-png debug

in your Config.prc file. It will enable the debug output for the PNG writer, which should tell you the decisions it is making about what kind of file to write out.


Well sure enough the debug output says: “more than 256 colors found; not making a palette image.” But when i open up the resulting .png in Adobe Fireworks, it only identifies 71 unique colors when I ask it to make a palette… so one of the two programs is doing something weird…

At any rate, it would be a great feature if possible to force outputting a png8, though I know that requires a palette-creation algorithm to be put in place.