<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content=text/html;charset=iso-8859-1>
<STYLE></STYLE>
<META content="MSHTML 6.00.2900.2722" name=GENERATOR></HEAD>
<BODY id=MailContainerBody
style="PADDING-LEFT: 10px; FONT-WEIGHT: normal; FONT-SIZE: 10pt; COLOR: #000000; BORDER-TOP-STYLE: none; PADDING-TOP: 15px; FONT-STYLE: normal; FONT-FAMILY: Verdana; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BORDER-BOTTOM-STYLE: none"
leftMargin=0 topMargin=0 acc_role="text" CanvasTabStop="true"
name="Compose message area"><!--[gte IE 5]><?xml:namespace prefix="v" /><?xml:namespace prefix="o" /><![endif]-->
<DIV><STRONG>Environment:</STRONG></DIV>
<DIV> </DIV>
<DIV>Windows XP</DIV>
<DIV>Python 2.4.1 with IDLE</DIV>
<DIV>PIL 1.1.5</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><STRONG>Problem:</STRONG></DIV>
<DIV> </DIV>
<DIV>My class 'Bildbeschrifter' is reading an image from background. The image
could be a .gif or a .png or a .jpg and nothing else. After opening the
Bildbeschrifter produces a text image with transparent background and the
same size as the opened image. Finally the Bildbeschrifter pastes the</DIV>
<DIV>text image to the opened image and saves the result on background.</DIV>
<DIV>My class is working fine with .jpg. But it does not with .gif and png. The
pasted text is not readable any longer. Here a .gif output of my class:</DIV>
<DIV><IMG
style="DISPLAY: inline-block; FLOAT: none; MARGIN: 0px; POSITION: static"
height=64 src="cid:002101c5b935$95c702e0$4A8D4257@Spacegate" width=154
border=0></DIV>
<DIV>What I am doing wrong?</DIV>
<DIV> </DIV>
<DIV><STRONG>Python Code (fragment):</STRONG></DIV>
<DIV><STRONG></STRONG> </DIV>
<DIV>(sorry for German identifiers)</DIV>
<DIV> </DIV>
<DIV>class Bildbeschrifter:</DIV>
<DIV> </DIV>
<DIV> def __init__(self, bild, zeilenliste,
font,
\<BR>
rand = 0, zeilenabstand =
4,
\<BR>
satz = 'mittig', schriftfarbe = (0x00, 0x00, 0x00,
0xFF)):<BR> if bild.urbild.bild and
bild.drehwinkel == 0 and
zeilenliste:<BR>
grund =
Image.open(bild.pfad)<BR>
zeilenhoehe =
font.zeilenausdehnung(zeilenliste[0])[1]<BR>
hoehe = 2 * rand + len(zeilenliste) * (zeilenhoehe + zeilenabstand) -
zeilenabstand<BR>
schreibgrund =
ImageDraw.Draw(grund)<BR>
zeilenbreiten =
[]<BR> breite
= 0<BR> for z
in
zeilenliste:<BR>
zb= 2 * rand +
font.zeilenausdehnung(z)[0]<BR>
zeilenbreiten.append(zb)<BR>
if breite <
zb:<BR>
breite =
zb<BR> if
breite <= grund.size[0] and hoehe <=
grund.size[1]:<BR>
folie = Image.new('RGBA', grund.size, (0xFF, 0xFF, 0xFF,
0x00))<BR>
schreibgrund =
ImageDraw.Draw(folie)<BR>
ausdehnung =
grund.size<BR>
h = (ausdehnung[1] - hoehe) / 2 +
rand<BR>
for i in range(0, len(zeilenliste),
1):<BR>
z =
zeilenliste[i]<BR>
if satz ==
'links':<BR>
links =
rand<BR>
elif satz ==
'rechts':<BR>
links = rand + ausdehnung[0] -
zeilenbreiten[i]<BR>
else:<BR>
links = rand + (ausdehnung[0] - zeilenbreiten[i]) /
2<BR>
schreibgrund.text((links, h), z, schriftfarbe,
font.font)<BR>
h = h + zeilenhoehe +
zeilenabstand<BR>
del
schreibgrund<BR>
grund.paste(folie, mask =
folie)<BR>
if bild.urbild.bildart ==
'.gif':<BR>
grund.save(bild.pfad, 'GIF',
**grund.info)<BR>
elif bild.urbild.bildart ==
'.png':<BR>
grund.save(bild.pfad, 'PNG',
**grund.info)<BR>
else:<BR>
grund.save(bild.pfad,
'JPEG')<BR>
<BR></DIV></BODY></HTML>