zoukankan      html  css  js  c++  java
  • php简单生成验证码图片

    <?php 
    $i=imagecreatetruecolor(100, 30);
    $iColor=imagecolorallocate($i, 240, 240, 240);
    imagefill($i, 0, 0, $iColor);
    $str="1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPSDFGHJKLZXCVBNM";
    $nStr=str_shuffle($str);
    $fourStr=substr($nStr, 0,4);
    
    for ($j=0; $j < strlen($fourStr); $j++) { 
    
        $s=substr($fourStr, $j,1);
        //随机颜色,尽量不要太浅(和底色白色有差别)
        $fColor=imagecolorallocate($i, mt_rand(0,150), mt_rand(0,150), mt_rand(0,150));
        //随机倾斜
        $angle=mt_rand(0,45);
    
        $x=8+$j*25;
        $y=25;
        //SIMYOU.TTF字体文件可以在C:WINDOWSFonts下找到,多个字体也可以添加到一个数组中,然后随机提取
        imagefttext($i, 20, $angle, $x, $y, $fColor, "SIMYOU.TTF", $s);
    }
    
    //添加干扰线 (4条干扰线)
    for ($j=0; $j < 4; $j++) { 
        $lColor=imagecolorallocate($i, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
        $x1=mt_rand(0,100);
        $y1=mt_rand(0,30);
        $x2=mt_rand(0,100);
        $y2=mt_rand(0,30);
    
        imageline($i, $x1, $y1, $x2, $y2, $lColor);
    }
    
    
    //加干扰点(200个干扰点)
    for ($j=0; $j < 200; $j++) { 
        $pColor=imagecolorallocate($i, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
        $x=mt_rand(0,100);
        $y=mt_rand(0,30);
        imagesetpixel($i, $x, $y, $pColor);
    }
    header("content-type:image/png");
    imagepng($i);
    
    ?>
  • 相关阅读:
    B. Pasha and Phone
    GCD(关于容斥原理)
    二分乘法
    Lucky7(容斥原理)
    E. Devu and Flowers
    最大公约数最小公倍数
    leetcode每日刷题计划--day55
    Titanic--kaggle竞赛入门-生存预测
    做题记录--day54
    机器学习上机作业1记录 && 相关知识点复习
  • 原文地址:https://www.cnblogs.com/xuxyblog/p/4233413.html
Copyright © 2011-2022 走看看