首頁 >後端開發 >php教程 >photoshop cs5 中文 解GD中文亂碼問題

photoshop cs5 中文 解GD中文亂碼問題

WBOY
WBOY原創
2016-07-29 08:36:181200瀏覽

今天仔細研究了下GD的一些相關技術,順手也研究下GD中文亂碼的問題。
  使用GD函式庫輸出中文字串,呼叫imagestring是沒有用的。需要使用imagettftext()函數。 imagettftext函數的具體使用就參考手冊啦。
  以下給予使用範例:
   

<span><code><span><br>$pic=imagecreate(250,30);  <br>$black=imagecolorallocate($pic,0,0,0);  <br>$white=imagecolorallocate($pic,255,255,255);  <br>$f><code><span><br><span><?php <BR>$pic</SPAN><SPAN>=</SPAN><SPAN>imagecreate</SPAN><SPAN>(</SPAN><SPAN>250</SPAN><SPAN>,</SPAN><SPAN>30</SPAN><SPAN>); <BR></SPAN><SPAN>$black</SPAN><SPAN>=</SPAN><SPAN>imagecolorallocate</SPAN><SPAN>(</SPAN><SPAN>$pic</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>); <BR></SPAN><SPAN>$white</SPAN><SPAN>=</SPAN><SPAN>imagecolorallocate</SPAN><SPAN>(</SPAN><SPAN>$pic</SPAN><SPAN>,</SPAN><SPAN>255</SPAN><SPAN>,</SPAN><SPAN>255</SPAN><SPAN>,</SPAN><SPAN>255</SPAN><SPAN>); <BR></SPAN><SPAN>$font</SPAN><SPAN>=</SPAN><SPAN>"C://WINDOWS//Fonts//simhei.ttf"</SPAN><SPAN>; <BR></SPAN><SPAN>$str </SPAN><SPAN>=</SPAN><SPAN>'php'</SPAN><SPAN>.</SPAN><SPAN>iconv</SPAN><SPAN>(</SPAN><SPAN>'gb2312'</SPAN><SPAN>,</SPAN><SPAN>'utf-8'</SPAN><SPAN>,</SPAN><SPAN>'面对对象'</SPAN><SPAN>).</SPAN><SPAN>" www.phpobject.net"</SPAN><SPAN>; <BR></SPAN><SPAN>imagettftext</SPAN><SPAN>(</SPAN><SPAN>$pic</SPAN><SPAN>,</SPAN><SPAN>10</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>10</SPAN><SPAN>,</SPAN><SPAN>20</SPAN><SPAN>,</SPAN><SPAN>$white</SPAN><SPAN>,</SPAN><SPAN>$font</SPAN><SPAN>,</SPAN><SPAN>$str</SPAN><SPAN>); <br></SPAN><SPAN>header</SPAN><SPAN>(</SPAN><SPAN>"Content-type: image/jpeg"</SPAN><SPAN>); <BR></SPAN><SPAN>$filename</SPAN><SPAN>=</SPAN><SPAN>'../src/images/photo.jpg'</SPAN><SPAN>; <BR></SPAN><SPAN>$im</SPAN><SPAN>=</SPAN><SPAN>imagecreatefromjpeg</SPAN><SPAN>(</SPAN><SPAN>$filename</SPAN><SPAN>); <BR></SPAN><SPAN>imagecopymerge</SPAN><SPAN>(</SPAN><SPAN>$im</SPAN><SPAN>,</SPAN><SPAN>$pic</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>250</SPAN><SPAN>,</SPAN><SPAN>30</SPAN><SPAN>,</SPAN><SPAN>50</SPAN><SPAN>); <BR></SPAN><SPAN>imagejpeg</SPAN><SPAN>(</SPAN><SPAN>$im</SPAN><SPAN>); <BR></SPAN><SPAN>?></span>   <br>     </span>$pic=imagecreate(250,30);  $black=imagecolorallocate($pic,0,0,0); 
$white=imagecolorallocate($ ,255,255,255); 
$f><span><p><span><?php   </p>$pic</span><span>=</span><span>imagecreate</span> <span>(</span><span>250</span><span>,</span><span>30</span><span>);  <p></p></span><span>$black<span>=</span><span>imagecolorallocate</span><span>(</span><span>$pic</span><span>,</span><span>0 SPAN><span>,</span><span>0</span><span>,</span><span>0</span><span>);  </span></span></span></p></span><span>$ white</span><span>=</span><span>imagecolorallocate</span><span>(</span><span>$pic</span><span>,</span><span>255 </span><span>,</span><span>255</span><span>,</span><span>255</span><span>);  </span><span>$font</span><span>=</span><span>"C://WINDOWS//Fonts//simhei.ttf"</span><span>;   </span><span>$str </span><span>=</span><span>'php'</span><span>.</span><span>iconv</span><span>(</span>'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 SPAN>,30,50); imagejpeg ($im); ?>          以上就介紹了photoshop cs5 中文 解決GD中文亂碼問題,包括了photoshop cs5 中文方面的內容,希望對PHP教程有興趣的朋友有所幫助。
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn