PHP简单制作验证码

    技术2024-12-02  17

    <?php header('Content-type:image/jpeg'); $width=120; $height=40; $element=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'); $string=''; for ($i=0;$i<4;$i++){ $string.=$element[rand(0, count($element)-1)];//循环出数组下标,并拼接数组 } //创建一个画布,即将在上面画画 $img=imagecreatetruecolor($width, $height); //定义颜色 $color=imagecolorallocate($img, rand(200,255), rand(200,255), rand(200,255)); $fontcolor=imagecolorallocate($img, rand(0,100), rand(0,100), rand(0,100)); imagefill($img, 0, 0, $color); //画一个像素 //imagesetpixel($img, rand(0,$width-1), rand(0,$height-1), $color); //画多个点 for ($i=0;$i<=500;$i++){ imagesetpixel($img, rand(0,$width-1), rand(0,$height-1), imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255))); } //输出字体 从左往右依次:图片资源,字体大小,字体倾斜度,第一个字体的坐标,水平,垂直,设置字体,写在文本的字符串 imagettftext($img, 25, rand(-5, 5), rand(8, 22), rand(20, 35), $fontcolor, 'font/Parisine-BoldItalic.woff.ttf', $string); //输出图片 imagejpeg($img); //销毁资源 imagedestroy($img); ?>
    Processed: 0.045, SQL: 9