PHP development verification code creation canvas

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

##imagedestroy($img);

Let’s take a look at the example

Create a canvas and set a color for it


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


Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!