PHP adds a digital watermark to the image to solve Chinese garbled characters. $ Textcolorimagecolorallocate ($ img, 255, 0, 0); set the watermark font color $ fontc: windowsfontssimhei. ttf; define the font $ texticonv (GB2312, UTF-8, $ waterImageUrl); move $ textcolor = imagecolorallocate ($ img, 255, 0, 0); // Set the watermark font color
$ Font = 'C:/windows/fonts/simhei. ttf'; // define the font
$ Text = iconv ("GB2312", "UTF-8", $ waterImageUrl); // convert the text to UTF8
Imagettftext ($ img, 20, 10, 50, 40, $ textcolor, $ font, $ text); // write text to the image
$ This-> outputImage ($ img, $ this-> getExtendsName ($ imageUrl), $ imageUrl );
Imagedestroy ($ img); // destroy the image
In many cases, the problem is solved in this way, but you should not forget it. in other special cases, you have set php page encoding, for example: header ("Content-Type: text/html; charset = UTF-8 ");
Well, at this time, you still use this way, it will be dead, the same will garbled, why, because it is already a UTF-8, what do you turn? You can remove the third line and change $ text in the imagettftext method to $ waterImageUrl. of course, there are more special cases, you pass the value of the page is other code, rather than the UTF-8, it is estimated that there are articles, so, I advise you to learn PHP friends, it is best to ensure that your website in each page encoding consistent, in this way, it is much easier to solve the problem.
Paste the code, for fear that some people do not know, www.2cto.com
$ Textcolor = imagecolorallocate ($ img, 255, 0, 0); // Set the watermark font color
$ Font = 'C:/windows/fonts/simhei. ttf'; // define the font
// $ Text = iconv ("UTF-8", "UTF-8", $ waterImageUrl); // convert the text to UTF8
// Actually we can see that there is no need to turn here, because I have set the encoding to UTF-8 in the previous index. php file, if
// Write to // $ text = iconv ("GB2312", "UTF-8", $ waterImageUrl); instead, garbled
$ Text = $ waterImageUrl;
Imagettftext ($ img, 20, 10, 50, 40, $ textcolor, $ font, $ text); // write text to the image
$ This-> outputImage ($ img, $ this-> getExtendsName ($ imageUrl), $ imageUrl );
Imagedestroy ($ img); // destroy the image
From 0 + 0 + 0 +... = 1
Watermark = imagecolorallocate ($ img, 255, 0, 0); // Set the watermark font color $ font = c:/windows/fonts/simhei. ttf; // define the font $ text = iconv (GB2312, UTF-8, $ waterImageUrl); // set...