Home > php教程 > php手册 > php 图片水印中文乱码解决方法

php 图片水印中文乱码解决方法

WBOY
Release: 2016-06-13 09:48:29
Original
1335 people have browsed it

php 图片水印中文乱码解决方法是要转入一款中文字体摩洛哥 以了,如果你在生成水印有中文时,又没载入相关的字体的话,那中文肯定会是乱码的,如果是英语字母那载不载入都没关系哦。

php教程  图片水印中文乱码解决方法是要转入一款中文字体摩洛哥 以了,如果你在生成水印有中文时,又没载入相关的字体的话,那中文肯定会是乱码的,如果是英语字母那载不载入都没关系哦。

$name =  iconv("gb2312","utf-8",www.bKjia.c0m 一聚教程网);
$font = 'simhei.ttf';//水印字体  
$im = imagecreatefromjpeg("test.jpg");//载入图片  
$black = imagecolorallocate($im, 0, 0, 0);//设置颜色  
imagettftext($im, 12, 0, 320, 84, $black, $font, $name);//打印水印  
imagepng($im);//输出图片,如果要保存加个保存路径和文件名,如imagepng($im,'test1.jpg');  
imagedestroy($im);//清空缓存 


下面来看一款生成水印文字函数

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);
    $col1=hex2dec($shadowcolor);#阴影颜色
    $col2=hex2dec($fontcolor);#字体颜色
    $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) {#十六进制颜色转换成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",10,"ffffff","330099",10,10[/url]);
?>

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template