[Image-SIG] Converting PNG RGB w/ transparency to PNG P w/ same

Ray Pasco pascor at hotpop.com
Thu Nov 4 01:22:17 CET 2004


I've sucessfully created a PNG RGB image with tranparency but am having 
trouble converting
it to a palettized PNG file format.  I've Googled all over but can't 
locate any reference.
What else do I need to do besides simple conversion ?  Here's the code:

import Image

# (mode, size, color=r,g,b), dark blue
imgRgb = Image.new ('RGB', (100, 100), (0, 85, 185))
# all alpha values = 255 (no transparency)
imgRgb = imgRgb.convert ('RGBA')

# paint new "alpha-tized" colors inside the image
# (r, g, b, a),  (L, Top, R, Bot)
imgRgb.paste ( (200,  85,   0,   255), ( 10,  10,    90,  90) )
imgRgb.paste ( (  0,   0,   0,     0), ( 20,  20,    80,  80) )

imgRgb.save ('TRANSPARENT.RGB.png')

# Now convert to a palettized format and save to a new file
imgPlt = imgRgb.convert ('P')
imgPlt.save ('TRANSPARENT.PLT.png')





More information about the Image-SIG mailing list