[Image-SIG] image.transform() data outside image boundaries

Fredrik Lundh fredrik at pythonware.com
Tue Mar 6 11:55:42 CET 2007

Christopher Schmidt wrote:

> When using image.transform, (EXTENT mode) it is possible to select an area
> which contains pixels outside the image:
>  out = im.transform((0,100), Image.EXTENT, (-50, -50, 50, 50))
> Is there a way to make these pixels transparent, or set their color in
> some way?

there's no direct way to do this in the current version of PIL, but you can get
the effect you're after by doing things in three steps:

    # transform the main image
    main = im.transform(size, mode, params)

    # create a mask
    mask = Image.new("L", im.size, 255).transform(size, mode, params)

    # paste the image onto an output image using the mask
    out = Image.new(mode, size, background)
    out.paste(main, mask)


More information about the Image-SIG mailing list