Transparency with PIL and paste ?

Discussion in 'Python' started by jean-Baptiste Cazier, Jul 23, 2003.

  1. 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()
     
    jean-Baptiste Cazier, Jul 23, 2003
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marek

    PIL and transparency in IE

    Marek, Jun 26, 2003, in forum: Python
    Replies:
    0
    Views:
    1,203
    Marek
    Jun 26, 2003
  2. Robin Becker

    PIL & TIFF transparency?

    Robin Becker, Jul 30, 2003, in forum: Python
    Replies:
    2
    Views:
    870
    Robin Becker
    Jul 31, 2003
  3. Gustavo Campanelli

    Newbie : Gif transparency with Pil problem.

    Gustavo Campanelli, Dec 15, 2003, in forum: Python
    Replies:
    2
    Views:
    453
    Gustavo Campanelli
    Dec 16, 2003
  4. Caleb Hattingh
    Replies:
    2
    Views:
    2,587
    Caleb Hattingh
    Dec 1, 2004
  5. Replies:
    2
    Views:
    738
    Max Erickson
    Aug 20, 2005
  6. tac-tics

    PIL - Transparency Nightmares

    tac-tics, Jul 10, 2006, in forum: Python
    Replies:
    1
    Views:
    413
    tac-tics
    Jul 10, 2006
  7. David

    PIL GIF transparency

    David, Sep 25, 2007, in forum: Python
    Replies:
    1
    Views:
    639
    Gabriel Genellina
    Sep 25, 2007
  8. Durand
    Replies:
    0
    Views:
    1,381
    Durand
    Jul 10, 2008
Loading...