ºÜ¶aÈ˲»Á˽a PHP ¿ÉÒÔ²uÉuÇHTMLµÄ×ÊÁÏ.ÕaÊǶԲuÉuÓ°Ïñͼdz£ÓÐÓõÄ.¿ÉÒÔ´Ó database ²uÉuÒ»¸o¼oµ¥µÄ¹a¸aeºaͼ»o¸u¼oµ¥Ö»²uÉuÒ»¸oͼÐΰ´Å¥ .
ÎÒÓà TTF ×ÖÐÍÔÚÒÔϵÄ*¶ÀýÖÐ
ÎÒͨ³£È¡Ãu×÷ '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);
?>
#######################################################
ºÜÖØÒªÒ»µaÊÇÄa²»ÄÜÔÚÕaµµ°¸ÖÐ*ÅÈκÎHTML tags.Ò²²»ÄÜÓпհ×ÐÐÔÚ <?ºÍ ?> tag ֮ǰ»oÖ®aa. Èç¹uÄaÓÃÕa¶ÎScriptaa¿´µ½Ò»¸o²»ÍeÕuµÄÓ°Ïñ, ±iʾÄa¿ÉÄÜÔÚPHP±eÇ(C)ÒÔÍaÎo´oÁË×ÖÔª.
ÒÔÉ쵀 script ¿ÉÒÔÓÉ´ËÓi*¨ÔÚÍøÒ³ÖнгoÀ´:
#######################################################
----test.php-----
test.php½a¹u»aÏñÕaÑu: .
's' ²ÎÊýÊÇÉe¶¨×ÖÐÍ´oС .
ÕaÊǵ± s=18 ʱ:
×¢I:
×ÖÐÍÂ*¾¶ "/fonts/TIMES.TTF" ¿ÉÓÉwindows/fontsĿ¼ÏÂÈ¡µÃ TIMS.TTF ×ÖÐ͵µ Copy ÖÁÄaÍøÕ¾µÄĿ¼ fontsϼ´¿É²aÊÔ ÖÁi¶ÖÐÎĵıiÏÖ Éдý¸÷λÍøÓÑÌa¹(C)ÐĵÃ
×¢Òa ÎÒÏÈ»ÁËÒ»¸oºÚÉ«½¿eÇøÔÙÓð×ɫλÒƲuÉu 3D Ч¹u.Ò²ÚiL¨ÔÚdzɫ±³¾°Öп´³oÀ´ µ«Äa¿ÉÒ԰ѱ³¾°É«¸ÄΪÉiÉ«¿´¿´´ËЧ¹u. ×ÖÐÍÒ²×oÁËͬÑuЧ¹u±iÏÖÁ¢Ìa¸Ð.
ÄaÒªÏÈȶ¨ÄaµÄ°²×° PHP ʱÓÐÉe¶¨Ö§Ô® GD ºÍ TTF. ¿É²Î¿¼ PHP FAQ . ÎÒ½¨Òe¿ÉÒÔ copy libgd.a µ½ /usr/local/lib ºÍ gd.h Ïa¹Øµµ°¸µ½ /usr/local/include È»aa
'make install' for FreeTTF library.
¿ÉÒÔÔÚÕahttp://rover.wiesbaden.netsurf.de/~kikita/ ÕÒµ½iÎhttf ×ÖÐÍŶ!
×¢:
ÒÔϵÄÔʼÂe¸Ä½øÁËÉÏÃaeµÄÛÍ?¿É¶aÐÐÎÄ×ÖÏÔʾ:
#######################################################
--------------button.php-----------------
<?
Header("Content-type: image/jpeg");
if(!isset($bgred)) $bgred=0;
if(!isset($bggreen)) $bggreen=51;
if(!isset($bgblue)) $bgblue=153;
if(!isset($chred)) $chred=255;
if(!isset($chgreen)) $chgreen=255;
if(!isset($chblue)) $chblue=255;
if(!isset($shadow)) $shadow="yes";
if(!isset($wrappos)) $wrappos=20;
if(!isset($crop)) $crop=2.2;
if(!isset($jpegquality)) $jpegquality=80;
if(!isset($s)) $s=11;
$savetext=$text;
$text=wordwrap($text,$wrappos," ",0);
if (!isset($font)) $fontname="/www/ttfonts/arialbd.ttf";
else
$fontname="/www/ttfonts/".$font.".ttf";
$size = imagettfbbox($s,0,$fontname,$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$upper=abs($size[5]);
$under=$size[1];
$th=$upper-$under;
$xpad=9;
if (substr_count($text,chr(13))>=1)
{
$mult=(substr_count($text,chr(13)));
$ypad=($mult$crop$s)+$s;
}
else $ypad=($crop-2)*$s;
$im = imagecreate($dx+$xpad,$th+$ypad);
$color = ImageColorAllocate($im, $bgred,$bggreen,$bgblue);
$black = ImageColorAllocate($im, 0,0,0);
$fontcolor = ImageColorAllocate($im, $chred,$chgreen,$chblue);
ImageRectangle($im,0,0,$dx+$xpad-1,$th+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$th+$ypad,$white);
if ($shadow=="yes")
ImageTTFText($im, $s, 0, (int)($xpad/2)-2+1, $th+2+(int)($ypad/2)-3, $black, $fontname, $text);
ImageTTFText($im, $s, 0, (int)($xpad/2)-2, $th+2+(int)($ypad/2)-1-3, $fontcolor, $fontname, $text);
Imagejpeg($im,"",$jpegquality);
ImageDestroy($im);
?>
#######################################################
Õa¿ÉÒÔÏÂÃaeÕa¸o form À´²uÉu:
#######################################################
----------test.php--------------------
»oÊÇÖ±½ÓÏñÉÏÀýÒ»Ñuºo½Ð:
#######################################################
----test.php-----