[cairo] erase memory

Ccx ccx at volny.cz
Tue Dec 6 07:06:25 PST 2005


Hello
I'm using pycairo and mod_python to generate server-side generated web
graphics.
All works fine except the memory block used for drawing isn't cleared in
any way, so strange artifacts appears sometimes on images.
How can I clear the memory? Note that I don't want to fill the
background with color, I want it to be transparent.
Thnx

The script is below:

from mod_python import apache
import cairo
import cStringIO

class CairoHandler:
        def __init__(self,width,height,format=cairo.FORMAT_ARGB32):
                self.sfc=cairo.ImageSurface(format,width,height)
                self.ctx = cairo.Context(self.sfc)
                self.width = width
                self.height = height
        def tostring(self):
                buffer = cStringIO.StringIO()
                self.sfc.write_to_png(buffer)
                str = buffer.getvalue()
                buffer.close()
                return str

def image(w,h,cmd):
    ch = CairoHandler(int(w),int(h))
    ctx = ch.ctx
   
    # DRAWING
    # ...

    return ch.tostring()

def handler(req):      
        req.content_type="image/png"
        data=req.uri.split('/').pop().strip('.png').split('x',2)
        cmd=data[2]
        h=data[1]
        w=data[0]
        req.write(image(w,h,cmd))
        return apache.OK



More information about the cairo mailing list