Everyone should pay attention, when learning to make verification codes, we need to open the manual
The function of making verification codes is relatively long
imagecreatetruecolor(); Create a canvas, let’s see below His syntax
Syntax:
resource imagecreatetruecolor (int $width, int $height)
Description: Return a Image identifier, width is $width and height is $height
Returns the image resource after success, returns FALSE after failure.
After we create a canvas, we need to assign a color to the canvas
imagecolorallocate
Syntax:
int imagecolorallocate ( resource $image , int $red , int $green , int $blue );
The first parameter,returns a resource type, and the subsequent parameters are in RGB format Color
How to output the image
header("content-type:image/png");
imagepng($image);
Destroy resources
<?php //第一步 创建一个画布 $image = imagecreatetruecolor(100, 30); //创建一个宽为100高为30的黑色图像 $bgcolor = imagecolorallocate($image, 255, 0, 0); //为图像分配颜色 imagefill($image,0,0,$bgcolor); //给黑色的背景图像分配白色 //输出图像 header("content-type:image/png"); imagepng($image); //销毁资源 imagedestroy($img); ?>As shown in the above code, we can see that a canvas with a width of 100, a height of 30 and a red background is output