php编程时乱码,php GD库中文乱码的解决方法

注意:在用GD库输出中文字符串时,要使用imagettftext()函数,调用imagestring()函数是不行的。

参考示例如下。

示例1:

$pic=imagecreate(250,30);

$black=imagecolorallocate($pic,0,0,0);

$white=imagecolorallocate($pic,255,255,255);

$font="C://WINDOWS//Fonts//simhei.ttf"; //必须是字符的路径

$str ='php'.iconv('gb2312','utf-8','面对对象')." www.jbxue.com";

imagettftext($pic,10,0,10,20,$white,$font,$str);

?>

示例2:文字水印。

/**

* GD库应用 文字水印

*/

$pic=imagecreate(250,30);

$black=imagecolorallocate($pic,0,0,0);

$white=imagecolorallocate($pic,255,255,255);

$font="C://WINDOWS//Fonts//simhei.ttf";

$str ='php'.iconv('gb2312','utf-8','面对对象')." www.jbxue.com";

imagettftext($pic,10,0,10,20,$white,$font,$str);

header("Content-type: image/jpeg");

$filename='../src/images/photo.jpg';

$im=imagecreatefromjpeg($filename);

imagecopymerge($im,$pic,0,0,0,0,250,30,50);

imagejpeg($im);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值