【www.gdgbn.com--按钮特效】

很多人不了解    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 可以由此语法在网页中叫出来:     
#######################################################

本文来源:http://www.gdgbn.com/wangyetexiao/2151/