Reading PNG data can only be done via writing to file
Bug #485348 reported by
James Fisher
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Cairo Plot |
New
|
Undecided
|
Unassigned |
Bug Description
It currently doesn't seem to be possible to read image data directly without first writing to file. For my needs (making a dynamic chart server) this is obviously grossly inefficient.
However the pycairo library does allow you to use file-like objects. I attach a quick fix using StringIO instead of a file. Use png_stream() in exactly the same way as commit, except that it returns a string in PNG format.
I've only *just* started with this small library but it looks like the problem is structural: functions/
Also, use of cStringIO would presumably be faster (?).
To post a comment you must log in.
Hello.
I have the same need as James Fisher here, so I built some more on his patch. Sorry if this is not the right way to deliver patches, but any way, here it is.
The patch basically just add support for an to_buffer argument, and if set True, the function will return a StringIO object containing the image. Maybe not the best way to do this, but at least it was a quick fix for my need.
Example:
'eur' : [7.8425, 7.8177, 7.8156, 7.8281, 7.8222, 7.833]} dot_line_ plot('currency. png', data=test_data, width=400, height=300, to_buffer=True)
test_data = {'usd' : [5.8962, 5.8472, 5.813, 5.7879, 5.8041, 5.7941],
img_buffer = CairoPlot.