<?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; ?>
动态输出文字(加水印),验证码二种方法
最新推荐文章于 2020-06-18 21:24:01 发布