Fastest way to tint an image with PIL

Dan Moskowitz danmoskowitz at gmail.com
Thu Nov 6 22:08:59 CET 2008


Hi,

I'm using PIL to tint and composite images together.  Here's how I'm
currently tinting images, it's really slow and I know there's got to
be a better way:

def TintImage( im, tintColor ):
	tint = (tintColor[0]/255.0, tintColor[1]/255.0, tintColor[2]/255.0,
tintColor[3]/255.0)
	pix = im.load()
	for x in xrange( im.size[0] ):
		for y in xrange( im.size[1] ):
			c = pix[x,y]
			pix[x,y] = (int(c[0]*tint[0]), int(c[1]*tint[1]),
int(c[2]*tint[2]), c[3])

I thought maybe there's a way to do it using the transform method, but
I haven't figure it out yet.  Anyone?

Thanks
-Dan



More information about the Python-list mailing list