Environment:
 
Windows XP
Python 2.4.1 with IDLE
PIL 1.1.5
 
 
Problem:
 
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
text image to the opened image and saves the result on background.
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:
What I am doing wrong?
 
Python Code (fragment):
 
(sorry for German identifiers)
 
class Bildbeschrifter:
 
    def __init__(self, bild, zeilenliste, font,                          \
                 rand = 0, zeilenabstand = 4,                            \
                 satz = 'mittig', schriftfarbe = (0x00, 0x00, 0x00, 0xFF)):
        if bild.urbild.bild and bild.drehwinkel == 0 and zeilenliste:
            grund = Image.open(bild.pfad)
            zeilenhoehe = font.zeilenausdehnung(zeilenliste[0])[1]
            hoehe = 2 * rand + len(zeilenliste) * (zeilenhoehe + zeilenabstand) - zeilenabstand
            schreibgrund = ImageDraw.Draw(grund)
            zeilenbreiten = []
            breite = 0
            for z in zeilenliste:
                zb= 2 * rand + font.zeilenausdehnung(z)[0]
                zeilenbreiten.append(zb)
                if breite < zb:
                    breite = zb
            if breite <= grund.size[0] and hoehe <= grund.size[1]:
                folie = Image.new('RGBA', grund.size, (0xFF, 0xFF, 0xFF, 0x00))
                schreibgrund = ImageDraw.Draw(folie)
                ausdehnung = grund.size
                h = (ausdehnung[1] - hoehe) / 2 + rand
                for i in range(0, len(zeilenliste), 1):
                    z = zeilenliste[i]
                    if satz == 'links':
                        links = rand
                    elif satz == 'rechts':
                        links = rand + ausdehnung[0] - zeilenbreiten[i]
                    else:
                        links = rand + (ausdehnung[0] - zeilenbreiten[i]) / 2
                    schreibgrund.text((links, h), z, schriftfarbe, font.font)
                    h = h + zeilenhoehe + zeilenabstand
                del schreibgrund
                grund.paste(folie, mask = folie)
                if bild.urbild.bildart == '.gif':
                    grund.save(bild.pfad, 'GIF', **grund.info)
                elif bild.urbild.bildart == '.png':
                    grund.save(bild.pfad, 'PNG', **grund.info)
                else:
                    grund.save(bild.pfad, 'JPEG')
               
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to