473,383 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Transparency with PIL and paste ?

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()
Jul 18 '05 #1
0 2806

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Caleb Hattingh | last post by:
Here's hoping effbot is around :) I have a really simple situation where I have 2 png images, and open them so: '>>> iconBallImage =...
20
by: Nathan Sokalski | last post by:
I am trying to create graphics with GDI+ that include transparency. However, the transparency never seems to show up, even though my colors have an alpha value of 0. How can I generate a graphic...
2
by: tvmaly | last post by:
I have been trying to add a watermark to a jpeg using PIL, but the watermark has a black box around it. I looked at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879 and ...
5
by: unknown | last post by:
I am trying to place a company logo on a form but try as I will I can not get the transparent parts to stay transparent. Is this even possible? If so what file format does my picture need to be...
3
by: Bob Hollness | last post by:
Transparent textboxes? Is it possible? When I try to set the Alpha of the colour it tells me that the control does not support transparency. If not, is there any other way I can do this?
6
by: tommaso.gastaldi | last post by:
In a previous post I have been asking about a way to test Alpha Transparency. Bob and Michael have kindly provided some ideas. Here I would like to share the function I have prepared, for the...
1
by: tac-tics | last post by:
I'm trying to make a simple script which attaches watermarks to every image in one directory and saves the output image to another. However, while I understand (in theory at least) what I need to...
1
by: David | last post by:
Hello alll, Apologies if this isn't the correct list. I'm getting my feet wet with the Python Imaging Library (PIL) 1.1.6 on Python 2.5.1. I have played around quite a bit with transparent...
0
by: Durand | last post by:
Hi! I'm trying to paste a png with a transparent layer into an image using "image.paste(tesla,(20,10), tesla)" but I'm getting this error: ValueError: bad transparency mask I have used...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.