PHP-PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.