[Image-SIG] feature request: 8-bit alpha transparency PNG;s
Tibor Arpas
tibor.arpas at infinit.sk
Fri Jan 23 16:34:41 CET 2009
Hi,
I'm using little attached program to convert my RGB and RGBA PNG's to png8.
But with RGBA pngs it's limited because it uses only GIF-like 1-bit
transparency. Seems that the alpha transparency in 8-bit (and 4-bit) PNG's
is little known or supported. But the main browsers seem to support it
including IE 6.0. One opensource utility which supports writing these is:
http://www.libpng.org/pub/png/apps/pngquant.html .
It would be greate if PIL would also do that.
Have a nice day,
Tibor
import Image
import random
import optparse
import sys
def quantize_and_invert(alpha):
if alpha <= 64: # You may change the threshold value into something
other.
return 255
return 0
im = Image.open(sys.argv[1])
if im.mode=='RGBA':
print "Warning, converting alpha transparency to 1-bit transparency"
al = im.split()[3]
al = Image.eval(al, quantize_and_invert)
colors=255
else:
al = None
colors=256
if im.mode!='RGB':
im = im.convert('RGB')
im=im.convert('P', palette=Image.ADAPTIVE, colors=colors)
if al: im.paste(255,None,al)
im.save('out.png',optimize=1, transparency=255)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/image-sig/attachments/20090123/2916def1/attachment-0001.htm>
More information about the Image-SIG
mailing list