Today, I have carefully studied some related GD technologies and studied the Chinese Garbled text of GD.
Using the GD library to output a Chinese string, it is useless to call imagestring. You need to use the imagettftext () function. For details about how to use the imagettftext function, refer to the manual.
Here is an example:
$ Pic = imagecreate (250,30 );
$ Black = imagecolorallocate ($ pic, 0, 0 );
$ White = imagecolorallocate ($ pic, 255,255,255 );
$ Font = "C: // WINDOWS // Fonts // simhei. ttf"; // The path here must be the character path.
$ Str = 'php'. iconv ('gb2312', 'utf-8', 'Face object'). "www.phpobject.net ";
Imagettftext ($ pic, 10, 0, 10, 20, $ white, $ font, $ str );
In the previous section, I provided a simple GD watermark example to illustrate how to use an image watermark. Here is a simple code for text watermark.
<? Php
$ Pic=Imagecreate(250,30);
$ Black=Imagecolorallocate($ Pic,0,0,0);
$ White=Imagecolorallocate($ Pic,255,255,255);
$ Font="C: // WINDOWS // Fonts // simhei. ttf";
$ Str='Php'.Iconv('Gb2312','Utf-8','Face Object')."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,30,50);
Imagejpeg($ Im);
?>