Douglas helped me off list, wanted to post the complete code in case
anyone else comes looking. So here's the code to rotate an image and
paste it onto another image without creating a black bounding box:
from PIL import Image
collage = Image.open("cheese.jpg")
# open the pic and give it an al
Alec Bennett wrote:
> collage.paste(im2, (30, 30) )
>From http://effbot.org/imagingbook/image.htm#Image.paste :
im.paste(image, box, mask)
Same as above, but updates only the regions indicated by the
mask. You can use either "1", "L" or "RGBA" images (in the latter
case, the alpha band
Alec Bennett wrote:
> Hmm, still getting a black box. The code as it stands now in case
> anything jumps out at you:
> # open the pic and give it an alpha channel so it's transparent
> im1 = Image.open("pic1.jpg")
> im1.convert('RGBA')
That should be
im1 = Image.open("pic1.jpg")
im1 = im1.conver
Hmm, still getting a black box. The code as it stands now in case
anything jumps out at you:
from PIL import Image
collage = Image.open("collage.jpg")
# open the pic and give it an alpha channel so it's transparent
im1 = Image.open("pic1.jpg")
im1.convert('RGBA')
# rotate it and expand it's ca
hi Alec,
> I'm trying to rotate an image and have the expanded background be transparent.
The image you get from opening a JPG won't have an alpha channel. You
need to add it yourself with the .convert() method.
This ought to work:
im = Image.open("pic1.jpg").convert('RGBA')
im2 = im.rotate(32,
I'm trying to rotate an image and have the expanded background be transparent.
For example:
im = Image.open("pic1.jpg")
im2 = im.rotate(32, expand = 1)
im2.show()
In the above, im2 is a copy of pic1.jpg that has been rotated 32
degrees. The problem is that the background over where it was rotate
I'm not sure exactly what you are showing me here. Perhaps you could
describe what you see (or even post the images). Prefixing the string
with spaces will of course prevent the problem, but introduces problems
of its own (how to accurately position the text, how to avoid the spaces
clobberin