文章發佈於 : 2004-09-13 00:32:53 | 文章分類 :
程式相關
這篇文章是由阿凱在Linuxfab所發表的,我一樣將他移轉過來.
請先到
http://board.justok.net/files/big5-uni.zip 下載這個檔案
<?php
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]","",$table[191*($h-129)+($l-64)]);
$rtext.= substr($uni,0,strlen($uni) - 1); // 此處原來有小bug...沒有去掉 unicode碼最後的換行.此處以修正
$i++;
}else{
$rtext.= $text[$i];
}
}
return $rtext;
}
// 以上使用含式庫中的 big5 轉 unicode 程式碼...
$id = ImageCreate (300, 300)
or die ("Cannot Initialize new GD image stream");
$black= ImageColorAllocate($id, 0, 0, 0);
$white= ImageColorAllocate($id, 250, 250, 250);
imagefill($id,0,0,$black);
// 將big5字串轉換為 unicode
$text = "這是測試";
$text = big52uni($text);
// imagettftext 含式的字串輸入必須是unicode 才能正確顯示自竄...
// 且要記得指定系統的字型路徑..
imagettftext($id,20,0,10,100,$white,"/usr/share/fonts/ttf/big5/bsmi00lp.ttf",$text);
Header("Content-type: image/gif");
ImagePNG($id);
imagedestroy($id)
?>
Love is waiting so you don't have to. Join Date.com for free!

Join
Asia FriendFinder the Largest Asian Dating Site on the Web for FREE!
Kaspersky Security for Internet Gateway 7.0
Know when to sell on eBay using research