[Image-SIG] [PIL]how to change the default fill color

Fredrik Lundh fredrik at pythonware.com
Tue Aug 15 23:49:06 CEST 2006


Bruce Who wrote:

> I'm a newbie to PIL, and is stumped with a issue: I use following
> statement to convert a image:
> 
> imout = im.transform((500,500),AFFIN,(1,0.5,0,0,0.5,0))
> 
> and I find out that some part of 'imout' is filled with black color,
> how to make PIL fill the area with other colors or just keep it
> transparent by default instead of just with black? I have searched the
> web and cannot get any ideas.
> 
> I'll appreciate any ideas. Thanks in advance.

there's no way to do this in 1.1.5; to get the result you want, you can 
warp a "solid" image using the same transform, and use that as a mask. 
something like this should work:

     size = 500, 500
     data = im.transform(size, AFFINE, (1,0.5,0,0,0.5,0))
     mask = Image.new("L", im.size, 255)
     mask = mask.transform(size, AFFINE, ...)
     imout = Image.new("RGB", size, "red")
     imout.paste(data, mask)

</F>



More information about the Image-SIG mailing list