php - mxGraph,将XML文件转换为PNG以导出图像的php代码
问题描述
我正在尝试使用 PHP 从 mxGraph 导出图像文件 (PNG)。我成功地将图形的 XML 字符串发送到 PHP 文件,我可以使用 mxUtils::parseXml(); 解析 XML 图书馆的指挥。我收到的输出仍然不可读。这是一个图像文件,但里面什么都没有。你能帮助我吗?这是我正在使用的 php 代码:
$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');
我不明白问题出在哪里。这是我上传的 XML 文件:
<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>
感谢你给与我的帮助!
解决方案
推荐阅读
- python - 一对多关系上的 NoForeignKeysError - SQLAlchemy
- node.js - 无法在通知 api 中运行 app.js | 社交板 | 节点.JS
- c# - 如何为 C# 命令行开关提供默认值
- c# - 单击删除按钮时如何防止DataTable中的Default?
- unity3d - 使用 Unity2D 创建一个类似于 Megaman 的角色选择屏幕
- python - 自定义 pytest 收集测试
- msvcrt - 在 Windows 7 嵌入式标准上安装 MSVC 可再发行组件
- javascript - 使用由 props 传递且不与给定事件关联的函数作为点击
- python - 在 pandas 的列中查找属于一起的元素
- testing - 更改加特林脚本中特殊字符的表示