如何在Graphviz中使用MetaPost生成的PostScript作为节点图像?
解决方法
方案1:转换图像格式为Graphviz兼容类型
Graphviz对PostScript格式的图像支持存在限制,优先将PS文件转换为PNG或PDF格式:
- 使用Ghostscript将PS转PNG:
gs -sDEVICE=pngalpha -o example1.png example.1 gs -sDEVICE=pngalpha -o example2.png example.2 - 更新
example.dot的图像路径:strict graph { { node [shape=none, label=""]; 1 [image="example1.png"]; 2 [image="example2.png"]; } 1 -- 2; } - 重新生成PS文件:
dot -Tps example.dot -o example.ps
方案2:检查文件路径与权限
- 确认
example.1、example.2与example.dot处于同一目录,且执行dot命令时的工作目录为该目录。 - 检查文件读取权限,若权限不足执行:
chmod +r example.1 example.2
方案3:直接嵌入PostScript代码(进阶)
若不想转换格式,可通过HTML标签嵌入PS文件,并指定对应尺寸(参考PS文件中的%%BoundingBox数值):
strict graph { node [shape=none]; 1 [label=< <img src="example.1" width="86" height="86"/> >]; 2 [label=< <img src="example.2" width="90" height="90"/> >]; 1 -- 2; }
内容的提问来源于stack exchange,提问作者Fabien
相关产品推荐
相关产品推荐

