PHP to image and digital watermark in Chinese garbled solution _php Tutorial

Source: Internet
Author: User
Tags learn php
$textcolor = Imagecolorallocate ($img, 255, 0, 0); Set Watermark Font Color
$font = ' C:/windows/fonts/simhei.ttf '; Defining fonts
$text = Iconv ("GB2312", "UTF-8", $WATERIMAGEURL); Convert Chinese text to UTF8
Imagettftext ($img, $textcolor, $font, $text);//write the text in the picture
$this->outputimage ($img, $this->getextendsname ($IMAGEURL), $IMAGEURL);
Imagedestroy ($img);///Destroy images

In many cases, the problem is such a solution, but, you don't forget, there are special circumstances, that is, you set the PHP page encoding, such as: Header ("content-type:text/html; Charset=utf-8 ");
, well, at this time, you still use this way, that will die, the same will garbled, why, because it is already UTF-8, you turn what ah? Not disorderly only strange, at this time, can be removed from the third line, the Imagettftext method directly to the $text to $waterimageurl, of course, there is a more special situation, that is, you pass the value of the page is another code, rather than UTF-8, that estimates there are articles, so, I would like to advise you to learn PHP friends, it is best to ensure that your site each page encoding consistent, so that the problem to solve a lot easier.
Or put the code, afraid some people do not know, www.2cto.com

$textcolor = Imagecolorallocate ($img, 255, 0, 0); Set Watermark Font Color
$font = ' C:/windows/fonts/simhei.ttf '; Defining fonts
$text = Iconv ("UTF-8", "UTF-8", $WATERIMAGEURL); Convert Chinese text to UTF8
As you can actually see, there's no need to go, because I've already set the encoding to UTF-8 in the previous index.php file, if
Written AS//$text = Iconv ("GB2312", "UTF-8", $WATERIMAGEURL); Instead, it will appear garbled.
$text = $WATERIMAGEURL;
Imagettftext ($img, $textcolor, $font, $text);//write the text in the picture
$this->outputimage ($img, $this->getextendsname ($IMAGEURL), $IMAGEURL);
Imagedestroy ($img);///Destroy images


Excerpted from 0+0+0+...=1

http://www.bkjia.com/PHPjc/478455.html www.bkjia.com true http://www.bkjia.com/PHPjc/478455.html techarticle $textcolor = imagecolorallocate ($img, 255, 0, 0);//Set watermark font Color $font = C:/windows/fonts/simhei.ttf;//define Font $text = Iconv (GB2312, UTF-8, $WATERIMAGEURL); Will be in ...

  • 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.