二 272007
一个简单的helper,可以根据自己需要扩展,比如加上中文支持等等:
GraphHelper.php
- <?php
- function ImgString($str)
- {
- $width = strlen($str)*7+10;
- $height = 22;
- $im = imagecreatetruecolor($width,$height);
- $bg = imagecolorallocate($im, 255, 255, 255);
- $textcolor = imagecolorallocate($im, 0, 0, 0);
- imagefill($im,0,0,$textcolor);
- imagefilledrectangle ($im, 1, 1, $width-2, $height-2, $bg );
- imagestring($im, 3, 6, 4, $str, $textcolor);
- header("Content-type: image/gif");
- imagegif($im);
- exit();
- }
- ?>
调用:
- <?php use_helper('Graph'); ?>
- <?php ImgString('123456')?>