1

I'm currently using Python Imaging Library's (PIL) transform with EXTENT function to allow users to do some basic editing of images i.e. simple zoom in / zoom out, x and y-axis offsets, set background color, rotation etc

And so one problem is that they are able to zoom out or offset enough so that parts of the final output image goes beyond the bounds of the source image. When this happens, PIL fills this portion with a black color

Does anybody know if there's a way to set a custom fill color rather than the black default or has any suggestions on ways to get around this? Much appreciated

I was originally thinking of pre-pasting an alpha layer to where the bounds are exceeded but this seems to get complicated quite quickly..

Dennis
  • 249
  • 1
  • 4
  • 17

1 Answers1

1

[Edit] Maybe this will help. So, do something like (don't pay too much attention to the exact integers ) ...

image2 = image1.transform((600, 400), Image.EXTENT, (0, 0, 1200, 800))

draw = ImageDraw.Draw(image2)

# Fill in rectangle below the real image
draw.rectangle( (0, 50, 1200, 600), fill=(255, 150, 0))

# Fill in rectangle to the right of the real image
draw.rectangle( (100, 0, 800, 50), fill=(150, 255, 0))
del draw

image2.save(SAVE_NAME)
HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
jcfollower
  • 3,103
  • 19
  • 25
  • I have to first pass the image through a transform though i.e. xoffset, zoom etc before being able to do a paste.. but once the transform happens the black fill is added – Dennis Sep 10 '15 at 13:34