动态输出文字(加水印),验证码二种方法

<?php //相片输出汉字,使用GD2函数imagegettfext(图像,字体大小,角度,x,y,color,) header("content-type:image/jpeg");//定义输出图像类型 $img=imagecreatefromjpeg("qykx/images/bg1.jpg");//载入相片 $textColor=imagecolorallocate($img, 25, 25, 236);//设置字体着色,RGB,若为水印,改色即可 $font="barcode\class\font\Arial.ttf";//字体,若字体不对,刚无法输出 $text="you are a dog"; $textCh=" 你是一只狗"; //iconv('GB2312', 'UTF-8',$textCh); imagettftext($img, 20, 0, 200, 200, $textColor, $font, $text);//写ttf字到图中 imagettftext($img, 40, 12, 100, 300, $textColor, $font, $textCh);//写ttf字到图中 imagejpeg($img);//建立jpeg图形 imagedestroy($img);//结束图形, ?> <?php //使用gd2函数生成验证码 $img = imagecreate(100, 25);// 建立一幅 100X30 的图像 $bg = imagecolorallocate($img, 223, 55, 255);// 白色背景和蓝色文本 $textColor = imagecolorallocate($img, 0, 0, 255); imagestring($img, 5, 0, 0, "Hello world!", $textColor);// 把字符串写在图像左上角 // 输出图像 header("Content-type: image/png"); imagepng($img);//生成png imagedestroy($img);//结束 ?> <?php //汉字验证码,事先做好汉字图片 $str=array("大","汉","字","验","证","码","试","试"); for($i=0;$i<4;$i++){ $num=rand(0,count($str)-1); $img.="<img src='images/".$num.".gif' width='16' height='16'>";//show your pic $pic.=$str[$num];//just for check right or wrong } echo $img; echo $pic; ?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值