PHP development verification code tutorial: Create verification code base map

Implementing the verification code base map

Before learning to make the verification code, you can view the manual of the GD library on php.cn for a better understanding. Functions required to create verification codes.

Create a base map of 100, 30 through the imagecreatetruecolor function

header('content-type: image/png');

Use the header method of php to output the content in the format of png

imagepeng($image);返回图片
imagedestroy($image);

It is convenient to destroy the image Recycling of system resources

Use imagecolorallocate to make a white filling

$bgcolor = imagecolorallocate($image,255,255,255);//#FFFFFFFFFFFF

Fill it into our base map

imagefill($image,0,0,$bgcolor);

Generates a white base map

QQ截图20161027113852.png

The color of the example image has been changed to make it easier for readers to see clearly

<?php
$image = imagecreatetruecolor(100,30);
$bgcolor = imagecolorallocate($image,000,255,255);//#FFFFFFFFFFFF
imagefill($image,0,0,$bgcolor);
header('content-type: image/png');
imagepng($image);
//销毁
imagedestroy($image);
?>

Note:

The default output of imagecreatetruecolor is black Background

Before outputting the image, the header information must be output in advance


Continuing Learning
||
<?php $image = imagecreatetruecolor(100,30); $bgcolor = imagecolorallocate($image,000,255,255);//#FFFFFFFFFFFF imagefill($image,0,0,$bgcolor); header('content-type: image/png'); imagepng($image); //销毁 imagedestroy($image); ?>
submitReset Code