> Nelson Minar <[EMAIL PROTECTED]> writes: > > > matplotlib is great, particularly the image quality. I'm using > > matplotlib to generate images in a webapp and have run into a problem. > > How do I get it to give me the rendered image bytes in a string rather > > than writing the image to a file? > > FigureCanvasAgg has the undocumented methods buffer_rgba, > tostring_argb, and tostring_rgb, which might help here. > > > The docs for FigureCanvasAgg.print_figure() says that if the filename > > is actually a file object then it will write the bytes to that file > > object. This works great if I pass in sys.stdout, but as soon as I try > > to use a StringIO() instance to capture the bytes in Python I get an > > error: > [...] > > TypeError: Could not convert object to file pointer > > libpng seems to require an actual file pointer. This was discussed in > http://thread.gmane.org/gmane.comp.python.matplotlib.general/3118/
libpng does not require a file pointer. It can write to streams (or StringIO objects) too. Cairo uses libpng to write to streams, and PyCairo uses cairo (and libpng) to write to file-like objects (like StringIO), so it is possible. But I don't know the details, the technique is buried somewhere in the cairo and libpng C code. Steve Send instant messages to your online friends http://au.messenger.yahoo.com ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users