Reading PNG data can only be done via writing to file

Bug #485348 reported by James Fisher
6
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/constructors accepting a filename rather than a file-like object.

Also, use of cStringIO would presumably be faster (?).

Revision history for this message
James Fisher (jameshfisher) wrote :
Revision history for this message
Rolf Håvard Blindheim (rhblind) wrote :

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:
test_data = {'usd' : [5.8962, 5.8472, 5.813, 5.7879, 5.8041, 5.7941],
                         'eur' : [7.8425, 7.8177, 7.8156, 7.8281, 7.8222, 7.833]}
img_buffer = CairoPlot.dot_line_plot('currency.png', data=test_data, width=400, height=300, to_buffer=True)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.