Home > php教程 > php手册 > body text

用PHP产生动态的影像图

WBOY
Release: 2016-06-13 12:40:17
Original
1148 people have browsed it

很多人不了解  PHP 可以产生非HTML的资料.这是对产生影像图非常有用的.可以从 database 产生一个简单的广告横图或更简单只产生一个图形按钮 .

我用 TTF 字型在以下的范例中  
我通常取名作 'button.php3':

#######################################################
-----button.php3------

  Header("Content-type: image/gif");
  if(!isset($s)) $s=11;
  $size = imagettfbbox($s,0,"fonts/TIMES.TTF",$text);
  $dx = abs($size[2]-$size[0]);
  $dy = abs($size[5]-$size[3]);
  $xpad=9;
  $ypad=9;
  $im = imagecreate($dx+$xpad,$dy+$ypad);
  $blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
  $black = ImageColorAllocate($im, 0,0,0);
  $white = ImageColorAllocate($im, 255,255,255);
  ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
  ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$white);
  ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "fonts/TIMES.TTF", $text);
  ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "fonts/TIMES.TTF", $text);
  ImageGif($im);
  ImageDestroy($im);
?>
#######################################################
很重要一点是你不能在这档案中放任何HTML tags.也不能有空白行在 tag 之前或之後. 如果你用这段Script後看到一个不完整的影像, 表示你可能在PHP标签以外误打了字元.

以上的 script 可以由此语法在网页中叫出来: 用PHP产生动态的影像图  

#######################################################
----test.php-----  




New Page 1


  

用PHP产生动态的影像图  



#######################################################  

test.php缁
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!