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  -  Image-SIG@python.org
http://mail.python.org/mailman/listinfo/image-sig

Reply via email to