zoukankan      html  css  js  c++  java
  • PHP

    ```php
    <?php
    header("content-type:image/jpeg");
    $width = 120;
    $height = 40;
    $img = imagecreatetruecolor($width,$height);

    $color_bg = imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));
    $color_str = imagecolorallocate($img,rand(10,100),rand(10,100),rand(10,100));
    $element = ['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'];
    $str = "";
    for($i=0;$i<5;$i++) {
        $str.=$element[rand(0,count($element)-1)];
    }

    imagefill($img,0,0,$color_bg);

    //imagesetpixel — 画一个单一像素
    //imagesetpixel( resource $image, int $x, int $y, int $color) : bool
    //imagesetpixel() 在 image 图像中用 color 颜色在 x,y 坐标(图像左上角为 0,0)上画一个点。
    //循环输出,可以重复输出点
        for($i=0;$i<100;$i++) {
            imagesetpixel($img,rand(0,$width-1),rand(0,$height-1),$color_str);
        }

        //循环输出多条线
        for($i=0;$i<3;$i++) {
            imageline($img,rand(0,$width/2),rand(0,$height),rand($width/2,$width),rand(0,$height),$color_str);
        }

        //imagettftext — 用 TrueType 字体向图像写入文本
        imagettftext($img,25,rand(-5,5),rand(5,15),rand(30,35),$color_str,'fonts/ywsfxs.ttf',$str);

    imagejpeg($img);
    //最后要释放内存
    imagedestroy($img);

    //金龙制作
    ```

    效果图;
    ![效果图片](https://img-blog.csdnimg.cn/20191110222350430.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjE5MDg5Mw==,size_16,color_FFFFFF,t_70)

  • 相关阅读:
    [转]一致性hash算法
    [转]算法的时间复杂度和空间复杂度详解
    [转]B树(多向平衡查找树)详解
    spring中ApplicationContextAware接口描述
    [转]web.xml中<url-pattern>详解
    [转]linux中vim命令
    [转]Java GC的原理
    [转]浅谈UML的概念和模型之UML九种图
    Jmeter做读取csv接口测试
    IDLE崩溃:IDLE's subprocess didn't make connection. Either IDLE can't start a...
  • 原文地址:https://www.cnblogs.com/wjlbk/p/12633457.html
Copyright © 2011-2022 走看看