输出中文字符
輸出中文字符
要想在圖形中輸出中文字符,需要對輸出的中文字符進(jìn)行編碼。使用iconv()函數(shù),可以把一種編碼的字符,轉(zhuǎn)換為其他編碼的字符。下面介紹在圖形中輸出中文字符的方法,
<?php
//創(chuàng)建一個(gè)新圖形
$image = imagecreate(400,200);
//設(shè)置背景,分配顏色
$bgColor = imagecolorallocate($image,250,250,250);
$black = imagecolorallocate($image,0,0,0);
//指定imagettftext()函數(shù)使用的字體
$font = “simhei.ttf”;
//字義要輸出的中文字符串
$string = “這是中文字符串”;
//對中文字符進(jìn)行編碼
$codeString = iconv(“GB2312″,”UTF-8″,$string);
//使用imagettftext()函數(shù)輸出文字
imagettftext($image,20,0,30,30,$black,$font,$codeString);
imagettftext($image,20,180,200,100,$black,$font,$codeString);
imagettftext($image,20,60,200,180,$black,$font,$codeString);
//輸出圖形
header(“Content-type: image/png”);
imagepng($image);
//釋放資源
imagedestroy($image);
?>
總結(jié)
- 上一篇: 在图形中使用指定字体
- 下一篇: 取得服务器支持的图形类型