1, the code is as follows:
<?php
function fillrandomstring () {
Generate Verification Code
$char = Array_merge (range (0, 9), Range ("A", "Z"), Range ("A", "Z"));
Talk about string $char upset
$luan = Str_shuffle (Implode ("", $char));
Randomly take four bits from a string
Return substr ($luan, 0,4);
}
Create a canvas
Header (' content-type:image/png ');
$height = 20;
$width = 80;
$image = Imagecreate ($width, $height);
$black = imagecolorallocate ($image, 0, 0, 0);
$white = Imagecolorallocate ($image, 255, 255, 255);
Draw a picture rectangle
Imagefilledrectangle ($image, 1, 1, $width-2, $height-2, $white);
padding string
Imagestring, $image, 4, fillrandomstring (), $black);
Output picture
Imagepng ($image);
Destroying pictures
Imagedestroy ($image);
However, the output on the browser is not displayed because the cache was not cleaned before output to the browser
Add code Ob_clean () before the header ();
This article is from the "Chensir" blog, make sure to keep this source http://sourliki.blog.51cto.com/4838492/1557635
PHP to use the GD library to draw pictures, make verification code browser can not output