Symfony添加文字输出为图片的helper
一个简单的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')?<
【作者: Liberal】【访问统计:】【2007年07月30日 星期一 10:05】【注册】【打印】
本文介绍了一个简单的Symfony Helper,可以将文字输出为图片。通过自定义的GraphHelper.php文件中的ImgString函数实现,该函数根据输入的字符串创建指定大小的图片,并将文字绘制到图片上。此外,还提供了调用此Helper的方法。
6103

被折叠的 条评论
为什么被折叠?



