[PIL]: Question On Changing Colour

jepler at unpythonic.net jepler at unpythonic.net
Wed Oct 12 04:22:00 CEST 2005


If you're always going from grey to tinted, then the easiest way is to 
treat it as a 'P' image with a special palette.

I believe this function will prepare the palette:
        def make_palette(tr, tg, tb):
            l = []
            for i in range(255):
                l.extend([tr*i / 255, tg*i / 255, tb*i / 255])
            return l

Here's an example:
	import Image

	A, B, C = map(chr, [64, 128, 192])
	i = Image.fromstring(
	    'P', (4,4), ''.join([
	    B,B,B,B,
	    B,C,C,A,
	    B,C,C,A,
	    B,A,A,A]))
	i.putpalette(make_palette(64,64,255))
	i.show()

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051011/2bf5de01/attachment.pgp>


More information about the Python-list mailing list