[Image-SIG] Is this a bug in PIL 1.1.5?

Stefan Spoettl spoettl at hotmail.com
Wed Sep 14 16:07:04 CEST 2005


Windows XP
Python 2.4.1 with IDLE
PIL 1.1.5


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]
                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]
                        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)
                    grund.save(bild.pfad, 'JPEG')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/image-sig/attachments/20050914/15fce2fe/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/gif
Size: 4413 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20050914/15fce2fe/attachment.gif

More information about the Image-SIG mailing list