我正在尝试将XML转换为图像。 XML是在grapheditor中创建的。运行代码时,在创建的图像上出现错误。我尝试使用image / png格式,仅使用“ png”格式。两者都给我错误。
<?php
// Includes the mxGraph library
include_once("_js/mxgraph/php/src/mxServer.php");
// XML to draw
$xml = '<mxGraphModel dx="1010" dy="595" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="3" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="1"><mxGeometry x="40" y="40" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>';
// Image
$format = "png";
header("Content-Disposition: attachment; filename=\"diagram.$format\"");
header("Content-Type: image/$format");
$image = mxGraphViewImageReader::convert($xml);
echo mxUtils::encodeImage($image, $format);
?>
错误:
<br />
<b>Fatal error</b>: Uncaught Error: Call to a member function getImage() on null in C:\Users\bruker\wamp64\www\inside\knowledge\_js\mxgraph\php\src\reader\mxGraphViewImageReader.php:273
Stack trace:
#0 C:\Users\bruker\wamp64\www\inside\knowledge\diagram_mxgraph_xml_to_png.php(151): mxGraphViewImageReader::convert('<mxGraphModel d...', '#FFFFFF')
#1 {main}
thrown in <b>C:\Users\bruker\wamp64\www\inside\knowledge\_js\mxgraph\php\src\reader\mxGraphViewImageReader.php</b> on line <b>273</b><br />