美文网首页
GD库做验证码基本步骤

GD库做验证码基本步骤

作者: 孤岛渔夫 | 来源:发表于2016-12-04 01:52 被阅读0次
    <?php 
    // 验证码
    // 
    // 1.创建真彩图
        $img = imagecreatetruecolor(150,50);
    // 2.分配颜色
        $back = imagecolorallocate($img, mt_rand(130,255),mt_rand(130,255),mt_rand(130,255));
        $font_color = imagecolorallocate($img, mt_rand(0,120),mt_rand(0,120),mt_rand(0,120));
    // 3.填充颜色
        imagefill($img, 0,0, $back);
    // 4.画图
        $str = implode(array_rand(array_flip(range('a','z')),4));
    // 
    // 
        imagettftext($img, 15, mt_rand(0,90) ,20,mt_rand(20,40),  $font_color, 'Arvo-Regular.ttf', $str);
    // 5.保存或者输出图片
        header('content-type:image/jpeg');
        imagejpeg($img);
    // 6.销毁资源
        imagedestroy($img);


 ?>

相关文章

网友评论

      本文标题:GD库做验证码基本步骤

      本文链接:https://www.haomeiwen.com/subject/kefhmttx.html