Home > Backend Development > PHP Tutorial > PHP image watermark Chinese garbled solution_PHP tutorial

PHP image watermark Chinese garbled solution_PHP tutorial

WBOY
Release: 2016-07-13 10:45:32
Original
937 people have browsed it

The solution to the Chinese garbled Chinese php image watermark is to transfer to a Chinese font Morocco. If you do not load the relevant fonts when generating the watermark with Chinese characters, then the Chinese will definitely be garbled. If it is It doesn’t matter if the English alphabet is loaded or not.

php tutorial The solution to the Chinese garbled image watermark is to transfer to a Chinese font Moroccan. If you do not load the relevant fonts when generating the watermark with Chinese, then the Chinese must be It will be garbled. If it is English letters, it doesn't matter whether it is loaded or not.

$name = iconv("gb2312","utf-8",www.bKjia.c0m Yiju Tutorial Network);
$font = 'simhei.ttf';//Watermark font
$im = imagecreatefromjpeg("test.jpg");//Load images
$black = imagecolorallocate($im, 0, 0, 0);//Set color
imagettftext($im, 12, 0, 320, 84, $black, $font, $name);//Print watermark
imagepng($im);//Output the image, if you want to save it, add a save path and file name, such as imagepng($im,'test1.jpg');
imagedestroy($im);//Clear cache


Let’s take a look at a function to generate watermark text

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 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);#Shadow color
$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($hexcolor) {#Convert hexadecimal color to 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" ,10,10[/url]);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633028.htmlTechArticlephp The solution to the Chinese garbled picture watermark is to transfer to a Chinese font Morocco. If you are generating a watermark When there is Chinese, if the relevant fonts are not loaded, the Chinese will definitely be...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template