Php image watermark Chinese garbled solution _ PHP Tutorial

Source: Internet
Author: User
Tags imagejpeg
Php image watermark Chinese garbled solution. 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, the Chinese character will certainly be a php image Watermark. The Chinese garbled solution is to transfer a Chinese font to Morocco. if you do not load the relevant font when the watermark is generated 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 );
}
?>
Str2pic ("[url = http://www.zhutiai.com] www. bKjia. c0m "," winter.jpg "," winter2.jpg "," simhei. ttf ", 10," ffffff "," 330099 ", [/url]);
?>

Http://www.bkjia.com/PHPjc/633028.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/633028.htmlTechArticlephp image watermark Chinese garbled solution is to be transferred to a Chinese font to Morocco, if you generate a watermark with Chinese, and did not load the relevant font, the Chinese will certainly be...

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.