這篇文章主要介紹了php的GD庫imagettftext函數解決中文亂碼問題,可通過將中文字符串轉為utf-8格式來解決,需要的朋友可以參考下
本文實例講述了php的GD庫imagettftext函數解決中文亂碼問題的方法。分享給大家供大家參考。具體如下:
使用imagettftext寫中文時,常出現亂碼問題。解決方法是將中文字符串轉為utf-8格式即可。具體代碼如下(文件格式為gb2312):
- <?php
- $im = imagecreatefromjpeg('./1.jpg');
- $w = imagesx($im);
- $h = imagesy($im);
- $green = imagecolorallocate($im,50,100,200);
- $str = iconv('gb2312','utf-8','幸福就在身邊');//解決亂碼問題
- imagettftext($im,16,0,200,100,$green,'./simhei.ttf',$str);
- header("content-type: image/jpeg");
- imagejpeg($im);
- imagedestroy($im);
- ?>
新聞熱點
疑難解答