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://www.cnblogs.com/wjlbk/p/11839339.html