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
my_font=ImageFont.load('/home/stat/Pygtk/PIL/Fonts/helvR12-ISO8859-1.pil')
#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()