Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4175392
  • 博文数量: 291
  • 博客积分: 8003
  • 博客等级: 大校
  • 技术积分: 4275
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-30 18:28
文章分类

全部博文(291)

文章存档

2017年(1)

2013年(47)

2012年(115)

2011年(121)

2010年(7)

分类: Python/Ruby

2011-05-10 21:30:11

graphviz是一款古老的画拓扑图的工具,非常强大,能够按照你在文本文件里定义的格式转换为拓扑图,很多大公司都是用graphviz来画拓扑图,它的最主要的功能是用程序生成文本,然后调用graphviz来把文本转化为拓扑图。
1.安装graphviz
到里下载对应的平台的安装包;
我用的是centos因此用yum安装最方便
  1. wget /etc/yum.repos.d/graphviz-rhel.repo
  2. yum install graphviz

2.安装完毕后进行测试

 

  1. echo “digraph G {Hello->World}” | dot -Tpng >hello.png

3.php 调用graphviz

首先用程序生成/tmp/domain.txt,然后用dot命令生成图片

 

 

  1. <?php
  2.    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

  3.    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified

  4.    header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1

  5.    header ("Pragma: no-cache"); // HTTP/1.0

  6.    header ("Content-type: image/gif");
  7.    $filename = '/tmp/domain.txt';
  8.    $somecontent = "digraph G {a->b->c->a}";
  9.     if (!$handle = fopen($filename, 'w')) {
  10.          echo "cannot open $filename";
  11.          exit;
  12.     }
  13.     if (fwrite($handle, $somecontent) === FALSE) {
  14.         echo "cannot write to $filename";
  15.         exit;
  16.     }
  17.     fclose($handle);

  18.    passthru("dot -Tpng $filename");
  19. // passthru("cat $filename | dot -Tpng");

  20. ?>

 

阅读(6373) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

kinfinger2011-05-11 09:15:04

不错,收藏了