一个简单的helper,可以根据自己需要扩展,比如加上中文支持等等:
GraphHelper.php

  1. <?php
  2. function ImgString($str)
  3. {
  4.     $width = strlen($str)*7+10;
  5.     $height = 22;
  6.    
  7.     $im = imagecreatetruecolor($width,$height);
  8.     $bg = imagecolorallocate($im, 255, 255, 255);
  9.     $textcolor = imagecolorallocate($im, 0, 0, 0);
  10.     imagefill($im,0,0,$textcolor);
  11.     imagefilledrectangle ($im, 1, 1, $width-2, $height-2, $bg );
  12.     imagestring($im, 3, 6, 4, $str, $textcolor);
  13.  
  14.    
  15.     header("Content-type: image/gif");
  16.     imagegif($im);
  17.     exit();   
  18. }
  19. ?>

调用:

  1. <?php use_helper('Graph'); ?>
  2. <?php ImgString('123456')?>

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

   
© 2011 刘敏的Blog Suffusion theme by Sayontan Sinha