Memory problem

Karel Soukup <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
Hello,

I use PIL 1.1.6 and Python 2.5. I have a simple method drawing a  
watermark into images. Input parameter is a URL of the original image  
and out is the watermarked image. The method works but after many  
calling the python process consumes more and more memory until it  
crashes totally.

Could anyone advise me how to solve the problem? Is there anything  
which I have to delete or close?

def draw_watermark(self, REQUEST):
        address = REQUEST.form['url']
        url = urllib.urlopen(address)
        fil = StringIO(url.read())
        url.close()
        img = Image.open(fil)
        fmt = img.format
        if img.mode != 'RGBA':
          img = img.convert('RGBA')
        COLOR = (255,255,255)
        draw = ImageDraw.Draw(img)
        f = ImageFont.truetype('C:/Windows/Fonts/Verdana.ttf', 11,  
encoding="unic")
        txt = "Copyrighted"
        draw.text((5,5), unicode(txt,'UTF-8'),  font=f, fill=COLOR)
        del draw
        out = StringIO()
        img.save(out, fmt)
        REQUEST = self.REQUEST
        REQUEST.RESPONSE.setHeader('Content-Type', fmt)
        return REQUEST.RESPONSE.write(out.getvalue())

Thank you in advance.

Karel
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.