array imagettftext(resource image,int size,int angle,int x,int y,int color, string fontfile, string text)
imagettftext() 將字符串 text 畫到 image 所代表的圖像上,從坐標 x,y(左上角為 0, 0)開始,角度為 angle,顏色為 color,使用 fontfile 所指定的 truetype 字體文件,根據 php 所使用的 gd 庫的不同,如果 fontfile 沒有以 '/'開頭,則 '.ttf' 將被加到文件名之后并且會搜索庫定義字體路徑,實例代碼如下:
- */
- //發送頭文件
- header("content-type: image/png");
- //創建圖像
- $im=imagecreatetruecolor(400, 30);
- //定義顏色
- $white=imagecolorallocate($im,255,255,255);
- $grey=imagecolorallocate($im,128,128,128);
- $black=imagecolorallocate($im,0,0,0);
- imagefilledrectangle($im, 0, 0, 399, 29, $white);
- //定義文本
- $text='hello world!';
- //這里是字體文件的路徑
- $font='arial.ttf';
- //為文字添加陰影,即為灰色畫出文本
- imagettftext($im,20,0,13,23,$grey,$font,$text);
- //添加文本,即用黑色畫出文本
- imagettftext($im,20,0,10,20,$black,$font,$text);
- //輸出png圖像
- imagepng($im);
- imagedestroy($im);
- //開源代碼Vevb.com
- /*
- 本函數同時需要 gd 庫和 freetype 庫。
- */
新聞熱點
疑難解答