[Image-SIG] Memory problem

Karel Soukup karel.soukup at me.com
Sat Jan 16 21:25:41 CET 2010


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())
        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,  
        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.


More information about the Image-SIG mailing list