Home > Article > Backend Development > Generate graphical verification code in php_PHP tutorial
We have talked a lot about generating graphical verification codes with PHP. This is a very simple tutorial suitable for beginners of PHP, a sample code for generating verification codes with PHP.
We have talked a lot about generating graphical verification codes in PHP tutorials. This is a very simple tutorial suitable for those who are getting started with PHP, with example codes for generating verification codes using PHP.
$height = 300;
$width = 300;
//Create background image
$im = ImageCreateTrueColor($width, $height);
//Assign color
$white = ImageColorAllocate ($im, 255, 255, 255);
$blue = ImageColorAllocate ($im, 0, 0, 64);
//Draw color to image
ImageFill($im, 0, 0, $blue);
//Draw string: Hello,PHP
ImageString($im, 10, 100, 120, 'Hello,PHP', $white);
//Output image, define header
Header ('Content-type: image/png');
//Send image to browser
ImagePng($im);
//Clear resources
ImageDestroy($im);
?>