Velocity Reviews > Transparency with PIL and paste ?

# Transparency with PIL and paste ?

jean-Baptiste Cazier
Guest
Posts: n/a

 07-23-2003
Sæl !

I am trying to rotate some text and paste it into a larger PIL Image.
( cannot use PyFT for some reasons)
However I have a problem of transparency and my new images in a box
shape are overlapping eventhough the test itself does not overlap.
I would like to avoid that problem using the transparency of the image
but without much success so far

Below is my code for Python2

Any help would be appreciated

Thanks

Jean-Baptiste

#!/usr/bin/python

import sys,math
sys.path.append("/home/stat/Pygtk/PIL/")
sys.path.append("/home/stat/Pygtk")

import Image,ImageDraw,ImageFont

def rotat(text,angle=70):
""" Rotation routine
returns the image and its size """

color=(220,120,010)
pangle=float(angle)*math.pi/180.0
[x,y]=my_font.getsize(text)
xy=x+y
timage=Image.new("RGBA", (2*xy,2*xy),(255,255,255,0))
draw=ImageDraw.Draw(timage)
draw.text((xy, xy-y), text,font=my_font,fill=color)
timage2=timage.rotate(angle)
X0=int(xy-math.sin(pangle)*y)
Y0=int(xy-x*math.sin(pangle)-y*math.cos(pangle))
X1=int(xy+math.cos(pangle)*x)
Y1=int(xy)
t3=timage2.crop((X0,Y0,X1,Y1))

return t3,X1-X0,Y1-Y0

#Create 2 new images
im,x_im,y_im=rotat("Mest the Test with M",45)
im2,x_im2,y_im2=rotat("new Test with T",20)

# Create an empy image
empty_image=Image.new("RGB", (500,300) ,(155,255,255))
empty_draw=ImageDraw.Draw(empty_image)
xs=0
xs2=xs+30
ys=0

# Paste new images
empty_image.paste(im,(xs,ys,xs+x_im,ys+y_im))
empty_image.paste(im2,(xs2,ys,xs2+x_im2,ys+y_im2))
empty_image.show()

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Durand Python 0 07-10-2008 08:31 PM Caleb Hattingh Python 2 12-01-2004 02:39 AM Gustavo Campanelli Python 2 12-16-2003 02:42 PM Robin Becker Python 2 07-31-2003 08:01 AM Marek Python 0 06-26-2003 07:08 AM