PHP Image Watermark Chinese garbled solution _php Tutorial

Source: Internet
Author: User
Tags imagejpeg
PHP Image Watermark Chinese garbled solution is to be transferred to a Chinese font in Morocco, if you create a watermark in Chinese, and did not load the relevant font, then the Chinese will certainly be garbled, if it is the English letter load does not matter oh.

PHP Tutorial Picture watermark Chinese garbled solution is to be transferred to a Chinese font in Morocco, if you create a watermark in Chinese, and did not load the relevant font, then the Chinese will certainly be garbled, if it is the English letter that load does not matter oh.

$name = Iconv ("gb2312", "Utf-8", www.bKjia.c0m-poly tutorial net);
$font = ' Simhei.ttf ';//Watermark Font
$im = Imagecreatefromjpeg ("test.jpg");//Load Picture
$black = imagecolorallocate ($im, 0, 0, 0);//Set color
Imagettftext ($im, 0, $black, $font, $name);//Print watermark
Imagepng ($im);//Output picture, if you want to save add a save path and file name, such as Imagepng ($im, ' test1.jpg ');
Imagedestroy ($im);//Empty Cache


Let's take a look at the Generate Watermark text 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]; #获取扩展名
if (eregi ("Jpg|jpeg", $pie)) $im = @imagecreatefromjpeg ($source);
if (Eregi (" GIF ", $pie)) $im = @imagecreatefromgif ($source);
if (eregi ("PNG", $pie)) $im = @imagecreatefrompng ($source);
$col 1=hex2dec ($shadowcolor); #阴影颜色
$col 2=hex2dec ($fontcolor); #字体颜色
$col 1=imagecolorallocate ($im, $col 1 [0], $col 1[1], $col 1[2]);
$col 2=imagecolorallocate ($im, $col 2[0], $col 2[1], $col 2[2]);
Imagettftext ($im, $fontsize, 0, $y +1, $x +1, $col 1, $fonturl, $string);
Imagettftext ($im, $fontsize, 0, $y, $x, $col 2, $fonturl, $string);
Imagejpeg ($im);
if ($destination) imagejpeg ($im, $destination);
Imagedestroy ($im);
}

function Hex2dec ($hexcolror) {#十六进制颜色转换成10进制颜色
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", Ten, "ffffff", " 330099 ", 10,10[/url]);
?>

http://www.bkjia.com/PHPjc/633028.html www.bkjia.com true http://www.bkjia.com/PHPjc/633028.html techarticle PHP Image Watermark Chinese garbled solution is to be transferred to a Chinese font in Morocco, if you create a watermark in Chinese, and did not load the relevant font, then 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.