Home > Article > Backend Development > photoshop cs5 Chinese solves GD Chinese garbled problem
Today I carefully studied some related technologies of GD, and also studied the problem of Chinese garbled characters in GD.
Use the GD library to output Chinese strings and calling imagestring is useless. You need to use the imagettftext() function. Please refer to the manual for the specific use of the imagettftext function.
Here is a usage example:
<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>255<SPAN></SPAN>,<SPAN></SPAN>255<SPAN> </SPAN>,<SPAN></SPAN>255<SPAN></SPAN>); <SPAN></SPAN><SPAN>$font</SPAN><SPAN>=</SPAN><SPAN>"C://WINDOWS//Fonts//simhei.ttf"</SPAN><SPAN>; </SPAN>'php' <SPAN></SPAN>.<SPAN><BR>iconv</SPAN><SPAN>(</SPAN><SPAN>'gb2312'</SPAN><SPAN>,</SPAN><SPAN>'utf-8'<BR></SPAN>,<SPAN></SPAN>'face object'<SPAN></SPAN>).<SPAN></SPAN>"www.phpobject.net"<SPAN> </SPAN>; <SPAN></SPAN><SPAN>imagettftext</SPAN><SPAN>(</SPAN><SPAN>$pic</SPAN><SPAN>,</SPAN><SPAN>10</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>10<BR></SPAN>,<SPAN></SPAN>20<SPAN></SPAN>, <SPAN></SPAN>$white<SPAN></SPAN>,<SPAN></SPAN>$font<SPAN> T, $ $ str</SPAN><SPAN>); </SPAN><SPAN></SPAN>Header<SPAN></SPAN> (<SPAN></SPAN> "Content-Type: Image/JPEG" <SPAN></SPAN>); photo.jpg'<SPAN></SPAN>; <SPAN></SPAN><SPAN>$im</SPAN><SPAN>=</SPAN><SPAN>imagecreatefromjpeg</SPAN><SPAN>(</SPAN><SPAN>$filename<br></SPAN>); <SPAN></SPAN><SPAN>imagecopymerge</SPAN><SPAN>(</SPAN><SPAN>$im <BR></SPAN>,<SPAN></SPAN>$pic<SPAN></SPAN>, <SPAN></SPAN>0<SPAN><BR>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,</SPAN><SPAN>0</SPAN><SPAN>,<BR></SPAN>250<SPAN></SPAN>,<SPAN></SPAN>30<SPAN></SPAN>,<SPAN></SPAN>50 <SPAN></SPAN>); <SPAN></SPAN><SPAN>imagejpeg</SPAN><SPAN>( </SPAN><SPAN>$im</SPAN><SPAN>); </SPAN><SPAN></SPAN>?><span> </span> <span></span><span></span> <span>
</span>
The above has introduced photoshop cs5 Chinese to solve the GD Chinese garbled problem, including photoshop cs5 Chinese content. I hope it will be helpful to friends who are interested in PHP tutorials. <span>
</span>
<span></span></span></span>