你總是花很多時(shí)間去做一些按紐吧,去設(shè)計(jì)一個(gè)好的按紐背景全部用它吧!
文字可以隨意更換!
<?
header( "content-type: image/gif");
if(!isset($s)) $s=11;
//times.tif可以是你喜歡的任何字體
$size = imagettfbbox($s,0, "/fonts/times.ttf",$text);
//設(shè)定長寬
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=9;
$ypad=9;
$im = imagecreate($dx+$xpad,$dy+$ypad);
//設(shè)定r,g,b
$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標(biāo)記,尤其不允許在<? and ?> 當(dāng)中加入!
調(diào)用時(shí)寫下面的代碼:
<img src="button.php3?s=36&text=php+is+cool">
s是圖片的大小 text是圖片的文字
趕快試一試吧!
作者:rasmus lerdorf