I am working with the Indigo library for a chemistry web project. In short, they wrote a nice Python interface for him, which I use through CGI. There are several output formats, including SVG and PNG. I'm not a Python professional, so I'm a little fixated on the idea of an author about a buffer. The following works:
from indigo import *
from indigo_renderer import *
from struct import *
print "Content-type: image/svg+xml"
print
indigo = Indigo()
renderer = IndigoRenderer(indigo);
mol1 = indigo.loadMolecule("ONc1cccc1");
indigo.setOption("render-output-format", "svg");
indigo.setOption("render-highlight-color-enabled", "true");
image = renderer.renderToBuffer(mol1);
output = image.tostring()
print output
Thus, the above code splashes out properly formatted SVG XML without any unwanted leading or tail characters. Firefox recognized the type of content and displayed it perfectly.
However, it’s hard for me to understand what I should do for PNG:
I change the code to:
from indigo import *
from indigo_renderer import *
from struct import *
print "Content-type: image/png"
print
indigo = Indigo()
renderer = IndigoRenderer(indigo);
mol1 = indigo.loadMolecule("ONc1cccc1");
indigo.setOption("render-output-format", "png");
indigo.setOption("render-highlight-color-enabled", "true");
image = renderer.renderToBuffer(mol1);
output = image
print output
and I get this (which I did not expect from PNG):
array('c', '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00[ truncated by me ]')
toString(), blob ( ), - . , , ( PHP) - , , , (, , , , ). , , .