3

I'm trying to export an image file (PNG) from mxGraph using PHP. I successfully send the XML string of the graph to the PHP file and I can parse the XML using the mxUtils::parseXml(); command of the library. Still the output I receive is unreadable. It's an image file but with nothing inside. can you help me? this is the php code i'm using:

$xml = mxUtils::readFile("graphmodel.xml");
$doc = mxUtils::parseXml($xml);

$model = new mxGraphModel();
$graph = new mxGraph($model);

$codec = new mxCodec($doc);
$codec->decode($doc->documentElement, $graph->model);

$image = $graph->createImage(null, "#FFFFFF");

imageInterlace($image, 1);
imageColorTransparent($image, imageColorAllocate($image, 255, 255, 255));

header("Content-Type: image/png");

echo mxUtils::encodeImage($image, 'png');

I don't understand where is the problem. This is the XML file I upload:

<mxGraphModel dx="876" dy="502" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="CIAO" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="20" y="20" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="4" value="Bella" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="250" y="20" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="5" value="" style="endArrow=classic;startArrow=classic;html=1;entryX=0;entryY=0.5;exitX=1;exitY=0.5;" edge="1" parent="1" source="2" target="4">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="20" y="150" as="sourcePoint"/>
<mxPoint x="70" y="100" as="targetPoint"/>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>

Thanks for any help you can give me!

MarcoRos
  • 33
  • 5
  • Hello - I am facing same problem , did you find the solution? I want to convert xml into image and store into db. Thanks in advance – Kushal Maniyar Mar 27 '20 at 12:02

0 Answers0