• PHP绘图案例讲解验证码制作


    <?php
    header("Content-type: image/png");//声明浏览器解析为图片
    $width=200;
    $height=100;
    $color1=imagecreate($width,$height); //绘制一个画布
    
    
        imagecolorallocate($color1, 60, 60, 40);//设置此选项后,画的点或者是线连接之后回成团,带颜色
        $color_T=imagecolorallocate($color1, rand(200,255), rand(200,255), rand(200,255));//随机数取颜色
        //矩形边框的颜色
        $color_B=imagecolorallocate($color1, rand(200,255), rand(200,255), rand(200,255));
        //字体颜色
        $colorString=imagecolorallocate($color1, rand(10,100), rand(10,100), rand(10,100));
        //画点    循环
        for($i=0;$i<100;$i++){
            imagesetpixel($color1, rand(0,$width-1), rand(0,$height-1),
                imagecolorallocate($color1, rand(100,200), rand(100,200), rand(100,200)));//画点函数
        }
        //画线
        for ($j=0;$j<5;$j++){
            imageline($color1, rand(0,$width-30),rand(0,$height), rand(0,$width/2),rand(0,$height),
                imagecolorallocate($color1, rand(100,200), rand(100,200), rand(100,200)));//画线函数
        }
    
        //写字
        /* imagestring($color1, 50, 0, 0, 'abcf', $colorString); *///两个不同的写字函数
        imagettftext($color1, 30,20, 0, 40, $colorString,'COMSC.TTF', 'abcv');//两个不同的写字函数
        //-------------------------------------------------------
        imagefill($color1, 0, 0, $color_T);//图像着色
        //画一个矩形
        imagerectangle($color1,0,0,$width-1, $height-1, $color_B);
        imagepng($color1);
    
  • 相关阅读:
    剑指 Offer 55
    剑指 Offer 55
    剑指 Offer 22. 链表中倒数第k个节点
    剑指 Offer 29. 顺时针打印矩阵
    剑指 Offer 17. 打印从1到最大的n位数
    剑指 Offer 57
    剑指 Offer 59
    B. Han Solo and Lazer Gun 暴力 水
    C. Number of Ways 思维
    C. Destroying Array 并查集/线段树 Intel Code Challenge Elimination Round (Div. 1 + Div. 2, combined)
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/11141676.html
Copyright © 2020-2023  润新知