Search Results

Search found 3 results on 1 pages for 'colinmarc'.

Page 1/1 | 1 

  • How to return an image in an HTTP response with CherryPy

    - by colinmarc
    I have code which generates a Cairo ImageSurface, and I expose it like so: def preview(...): surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ... cherrypy.response.headers['Content-Type'] = "image/png" return surface.get_data() preview.exposed = True This doesn't work (browsers report that the image has errors). I've tested that surface.write_to_png('test.png') works, but I'm not sure what to dump the data into to return it. I'm guessing some file-like object? According to the pycairo documentation, get_data() returns a buffer. I've also now tried: tempf = os.tmpfile() surface.write_to_png(tempf) return tempf Also, is it better to create and hold this image in memory (like I'm trying to do) or write it to disk as a temp file and serve it from there? I only need the image once, then it can be discarded.

    Read the article

  • Python imports by folder module

    - by colinmarc
    I have a directory structure: example.py templates/ __init__.py a.py b.py a.py and b.py have only one class, named the same as the file (because they are cheetah templates). For purely style reasons, I want to be able to import and use these classes in example.py like so: import templates t = templates.a() Right now I do that by having this in the template folder's __init__.py: __all__ = ["a", "b"] from . import * However, this seems pretty poor (and maybe superfluous), and doesn't even do what I want, as I have to use the classes like this: t = templates.a.a() Thoughts?

    Read the article

  • rsvg doesn't render linked images

    - by colinmarc
    I use the python rsvg bindings to render an svg image into cairo and save to file, which mostly works. But if the svg file contains a linked image, like so: <image href="static/usrimgs/tmpDtIKpx.png" x="10" y="10" width="600px" height="400px"></image> the image doesn't show up in the final file (the rest of the svg renders just fine). The relative path is correct based on where the script is running, but I'm guessing there's some problem with the fact that it would normally be a relative URL, not a relative filepath. How do I get around this?

    Read the article

1