GD库做验证码基本步骤

2016-12-04  本文已影响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);


 ?>
上一篇 下一篇

猜你喜欢

热点阅读