透明的百葉窗價格-通風、調光、防光鋁百葉窗簾
窗簾、壁紙、地磚、地毯整體設計
隔音窗一通電話馬上服務!拆除工程專門
經驗老道處理迅速,親民價格高CP速洽

首頁  •  j2h 論壇 • 程式設計討論     • 

imagettftext使用中文字體

房東:阿龍
發表時間:2007-03-25




中文測試檔:

Header ("Content-type: image/gif");
$im = imagecreate (400, 30);
$black = ImageColorAllocate ($im, 0, 0, 0);
$white = ImageColorAllocate ($im, 255, 255, 255);
ImageTTFText ($im, 20, 0, 10, 20, $white,
"/usr/X11R6/lib/X11/fonts/TrueType/moe_kai.ttf", "這是中文測試 許功蓋 ");
ImagePng ($im);
ImageDestroy ($im);
?>

以上是 patch source 的做法,或是使用 unicode 也可以讓中文正常的顯示,以下就是 big5 轉 unicode 的做法。

function big52uni($text){
$rtext="";
$table=file("big5-uni.txt");
$max=strlen($text);
for($i=0;$i<$max;$i++){
$h=ord($text[$i]);
$l=ord($text[$i+1]);
if($h>=160 && $i<$max-1){
$uni=ereg_replace(".{5}([0-9]*)[\xd|\xa]","&#\\1;",$table[191*($h-129)+($l-64)]);
$rtext.=$uni;
$i++;
}else{
$rtext.=$text[$i];
}
}
return $rtext;
}
?>

用法的範例如下:

Header("Content-type: image/gif");
$im = imagecreate(400,30);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
// 以下是輸出標楷體中文,至於中文字形檔位置請根據自己電腦做修改
// 還有big52uni這個function在上面有,請自行複製過去用
// 備註:您必需裝GD及FreeType的套件才能輸出TTF字型
ImageTTFText($im, 20, 0, 10, 20, $white, "/usr/X11R6/lib/X11/fonts/TrueType/moe_kai.ttf", big52uni("Test中文測試"));
ImageGif($im);
ImageDestroy($im);
?>











header("Content-type: image/jpeg");
$im = imagecreate(400,30);
$white = imagecolorallocate($im, 255,255,255);
$black = imagecolorallocate($im, 0,0,0);
$string = iconv("GB2312", "UTF-8", "我");
$font = "c:/windows/fonts/SIMHEI.TTF";
// Replace path by your own font path
imagettftext($im, 20, 0, 10, 20, $black, $font, $string);
imagejpeg($im);
imagedestroy($im);
?>



  • 贊助網站       

    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務
    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!

  • 1 樓住戶:饅頭
    發表時間:2007-03-28

    //如果你要將IP顯示在一張空白的圖上
    header ("Content-type: image/jpeg");
    $im = imagecreate (200, 50); //開一張200*50的空白圖檔
    $img = ImageColorAllocate ($im, 255, 255, 0); //設定背景為黃色
    $textColor = ImageColorAllocate ($im, 255, 0, 0); //設定字的顏色為紅色
    imagestring ($im,5, 20 , 20,j2h,$textColor);
    //5, 20 , 20 = 字體 , x軸位置 , y軸位置
    imagejpeg ($im);
    imagedestroy ($im);
    ?>

    //如果你要將IP顯示在原本已存在的圖上
    $imgname = '05.jpg';
    $im = ImageCreateFromJPEG ($imgname);
    $textColor = ImageColorAllocate ($im, 255, 0, 0);
    ImageString ($im, 5, 20 , 20, $_SERVER['REMOTE_ADDR'] , $textColor);
    Header("Content-type: image/jpeg");
    imagejpeg($im);
    imagedestroy ($im);
    ?>





     共 1 人回應  選擇頁數 【第1 頁】 

    姓名:
    佈告內容:
    其他選項: