下面是生成文字水印的参数!但是有个问题,就是使用UTF-8编码,就无法生成中文水印,使用GBK编码就可以!
各位大侠,小弟不才,刚接触php。请问使用UTF-8编码该如何解决这个问题呢?<?php
/*
 * Created on 2011-11-25
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */ $image='cjxs.png';
$img = GetImageSize($image);switch($img[2])
{
case 1:
$im=@ImageCreateFromGIF($image);
break;
case 2:
$im=@ImageCreateFromJPEG($image);
break;
case 3:
$im=@ImageCreateFromPNG($image);
break;
}$logo='0001.jpg'; //头像文件,名称就以用户的腾讯微博的账户名
$ing = GetImageSize($logo);switch($ing[2])
{
case 1:
$in=@ImageCreateFromGIF($logo);
break;
case 2:
$in=@ImageCreateFromJPEG($logo);
break;
case 3:
$in=@ImageCreateFromPNG($logo);
break;
}//检测输入$username = $_POST['username'];
$usersex = $_POST['usersex'];
$userage = $_POST['userage'];
$sj=date('Y.m.d',time()+(60*60*8));imagecopy($im,$in,359,22,0,0,'100','100');
$te=imagecolorallocate($im, 9, 184, 186);
$str=iconv("gbk","UTF-8","$username");imagettftext($im,20,0,349,169,$te,'1.ttf',$str);
$te=imagecolorallocate($im, 9, 184, 186);
$str=iconv("gbk","UTF-8","$usersex");imagettftext($im,20,0,349,197,$te,'1.ttf',$str);
$te=imagecolorallocate($im, 9, 184, 186);
$str=iconv("gbk","UTF-8","$userage");
imagettftext($im,20,0,443,197,$te,'1.ttf',$str);
$te=imagecolorallocate($im, 9, 184, 186);
$str=iconv("gbk","UTF-8","$sj");
imagettftext($im,10,0,343,220,$te,'1.ttf',$str);
//// 输出图像
//header("Content-type: image/png");
if(ImagePng($im,'188.png'));{
echo "成功水印";
}
?>