|
使用GD庫輸出中文字符串,調用imagestring是沒有用的。需要使用imagettftext()函數。imagettftext函數的具體使用就參考手冊啦。
下面給個使用實例:
$pic=imagecreate(250,30);
$black=imagecolorallocate($pic,0,0,0);
$white=imagecolorallocate($pic,255,255,255);
$font="C://WINDOWS//Fonts//simhei.ttf"; //這里的路進需要注意下,必須是字符的路徑
$str ='php'.iconv('gb2312','utf-8','面對對象')." www.phpobject.NET";
imagettftext($pic,10,0,10,20,$white,$font,$str);
前面我給出一個簡單的GD水印實例,只舉例說明了使用圖片如何水印的,這里給出一個文字水印的簡單代碼。
<?php
$pic=imagecreate(250,30);
$black=imagecolorallocate($pic,0,0,0);
$white=imagecolorallocate($pic,255,255,255);
$font="C://WINDOWS//Fonts//simhei.ttf";
$str ='php'.iconv('gb2312','utf-8','面對對象')." www.phpobject.NET";
imagettftext($pic,10,0,10,20,$white,$font,$str);
header("Content-type: image/jpeg");
$filename='../src/images/photo.jpg';
$im=imagecreatefromjpeg($filename);
imagecopymerge($im,$pic,0,0,0,0,250,30,50);
imagejpeg($im);
?>
php技術:解決GD中文亂碼問題,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。