发新话题
打印

为 Symfony 添加文字并输出为图片的 helper

为 Symfony 添加文字并输出为图片的 helper

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')?>
一個偽裝成白癡的天纔!

TOP

发新话题