<?php
Header("Content-type: image/PNG");
$str="中文内容请多放些";
$imgWidth = 1000;//图片宽度
$imgHeight = 40; //图片高度
$authimg = imagecreate($imgWidth,$imgHeight);
$bgColor = ImageColorAllocate($authimg,255,255,255);
$fontfile = "msyh.ttf";
$white=imagecolorallocate($authimg,234,185,95);
//干扰线
imagearc($authimg, 150, 8, 20, 20, 75, 170, $white);
imagearc($authimg, 180, 7,50, 30, 75, 175, $white);
imageline($authimg,20,20,180,30,$white);
imageline($authimg,20,18,170,50,$white);
imageline($authimg,25,50,80,50,$white);
$noise_num = 800;
$line_num = 20;
imagecolorallocate($authimg,0xff,0xff,0xff);
$rectangle_color=imagecolorallocate($authimg,0xAA,0xAA,0xAA);
$noise_color=imagecolorallocate($authimg,0x00,0x00,0x00);
$font_color=imagecolorallocate($authimg,0x00,0x00,0x00);
$line_color=imagecolorallocate($authimg,0x00,0x00,0x00);
//干扰点点点
for($i=0;$i<$noise_num;$i++){
imagesetpixel($authimg,mt_rand(0,$imgWidth),mt_rand(0,$imgHeight),$noise_color);
}
//干扰线
for($i=0;$i<$line_num;$i++){
imageline($authimg,mt_rand(0,$imgWidth),mt_rand(0,$imgHeight),mt_rand(0,$imgWidth),mt_rand(0,$imgHeight),$line_color);
}
//随机
$randnum=rand(0,strlen($str)-4);
if($randnum%2)$randnum+=1;
$str = substr($str,$randnum,8);
$str = iconv("UTF-8","UTF-8",$str);
imagettftext($authimg, 9, 0, 0, 14, $font_color, $fontfile, $str);
imagepng($authimg);
imagedestroy($authimg);
?>
php 生成中文验证码
最新推荐文章于 2021-03-11 15:33:13 发布