[Image-SIG] image.transform problem
Fredrik Lundh
fredrik at pythonware.com
Thu Sep 15 09:57:09 CEST 2005
"akonsu" <akonsu at gmail.com> wrote:
> Hello, is there a way to change the colour of the background that is
> output when performing an image transform?
>
> image = Image.new("L", w, h, 0xff)
> ...
> image = image.transform(image.size, Image.QUAD, (0, 0, 0, 2 * h, w -
> 1, h - 1, w - 1, 0))
>
> produces black area at the bottom (or wherever the destination image
> does not correspond to the source image)
in current PIL versions, you have to resort to brute force (which isn't
that bad, really):
mask = Image.new("1", image.size, 1)
image = image.transform(... params ...)
mask = mask.transform(... same params ...)
out = Image.new(image.mode, image.size, background_color)
out.paste(image, mask)
(if you're not using NEAREST sampling, you can try using a "L" mask
instead, with the pixels set to 255)
</F>
More information about the Image-SIG
mailing list