range
array_merge
imagefontwidth
imagefontheighht
imagesetpixel
imageline
imagearc
<?php
$width = 200;
$height = 40;
$image = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, $width, $height, $white);
function getRandColor($image)
{
return imagecolorallocate($image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
}
//0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$string = join('', array_merge(range(0, 9), range('a', 'z'), range('A', 'Z')));
$textWidth = imagefontwidth(28);//9
$textHeight = imagefontheight(28);//15
$length = 4;
for ($i = 0; $i < 4; $i++) {
$randColor = getRandColor($image);
$size = mt_rand(20, 28);
$angle = mt_rand(-15, 15);
// $x = 20 + 40 * $i;
// $y = 30;
$x = ($width / $length) * $i + $textWidth;
$y = mt_rand($height / 2, $height - $textHeight);
$fontFile = 'fonts/courbi.ttf';
$text = str_shuffle($string);
imagettftext($image, $size, $angle, $x, $y, $randColor, $fontFile, $text{0});
}
for ($i = 1; $i <= 50; $i++) {
imagesetpixel($image, mt_rand(0, $width), mt_rand(0, $height), getRandColor($image));
}
//绘制线段
for ($i = 1; $i <= 3; $i++) {
imageline($image, mt_rand(0, $width), mt_rand(0, $height),
mt_rand(0, $width), mt_rand(0, $height), getRandColor($image));
}
//绘制圆弧
for ($i = 1; $i <= 2; $i++) {
imagearc($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width / 2),
mt_rand(0, $height / 2), mt_rand(0, 360), mt_rand(0, 360), getRandColor($image));
}
header('content-type:image/png');
imagepng($image);
imagedestroy($image);
?>
Paste_Image.png