Php image watermark Chinese garbled solution is to transfer a Chinese font to Morocco, if you did not load the relevant font when generating the watermark with Chinese characters, chinese characters will certainly be garbled. If it is English letters, it does not matter if it is not loaded.
Php tutorial image watermark Chinese garbled SolutionI want to transfer a Chinese font to Morocco. If you didn't load the relevant font when generating a watermark that contains Chinese characters, the Chinese characters will certainly be garbled, it doesn't matter if it's English letters.
$ Name = iconv ("gb2312", "UTF-8", www. bKjia. c0m );
$ Font = 'simhei. ttf'; // watermark font
$ Im = imagecreatefromjpeg ("test.jpg"); // load the image
$ Black = imagecolorallocate ($ im, 0, 0, 0); // set the color
Imagettftext ($ im, 12, 0,320, 84, $ black, $ font, $ name); // print the watermark
Imagepng ($ im); // output image. If you want to save the image with a save letter and a file name, for example, imagepng(saved im,'test1.jpg ');
Imagedestroy ($ im); // clear the cache
The following describes a watermark text generation function.
Function str2pic ($ string, $ source, $ destination = "", $ f, $ fontsize = 10, $ shadowcolor = "# ffffff", $ f, $ x = 10, $ y = 10 ){
// Header ('content-type: image/png ');
$ Pi = pathinfo ($ source );
$ Pie = $ pi [extension]; # Get the extension
If (eregi ("jpg | jpeg", $ pie) $ im = @ imagecreatefromjpeg ($ source );
If (eregi ("gif", $ pie) $ im = @ imagecreatefromgif ($ source );
If (eregi ("png", $ pie) $ im = @ imagecreatefrompng ($ source );
$ Col1 = hex2dec ($ shadowcolor); # shadowcolor
$ Col2 = hex2dec ($ fontcolor); # font color
$ Col1 = imagecolorallocate ($ im, $ col1 [0], $ col1 [1], $ col1 [2]);
$ Col2 = imagecolorallocate ($ im, $ col2 [0], $ col2 [1], $ col2 [2]);
Imagettftext ($ im, $ fontsize, 0, $ y + 1, $ x + 1, $ col1, $ fonturl, $ string );
Imagettftext ($ im, $ fontsize, 0, $ y, $ x, $ col2, $ fonturl, $ string );
Imagejpeg ($ im );
If ($ destination) imagejpeg ($ im, $ destination );
Imagedestroy ($ im );
}
Function hex2dec ($ hexcolror) {# convert a hexadecimal color to a decimal color
Preg_match_all ("/([0-f]) {2, 2}/I", $ hexcolror, $ matches );
If (count ($ matches [0]) = 3 ){
$ Rr = hexdec ($ matches [0] [0]);
$ Gg = hexdec ($ matches [0] [1]);
$ Bb = hexdec ($ matches [0] [2]);
}
Return array ($ rr, $ gg, $ bb );
}
?>
<? Php
Str2pic ("[url = http://www.zhutiai.com] www. bKjia. c0m "," winter.jpg "," winter2.jpg "," simhei. ttf ", 10," ffffff "," 330099 ", [/url]);
?>