Home >Backend Development >PHP Tutorial >Simple verification code generation, simple verification code generation_PHP tutorial
for($i=0;$i<5;$i ){
$rand .= dechex(rand(1,15)); // Random number hexadecimal 1-F generates 5
}
$im = imagecreatetruecolor(100,30); // Verification code size (artboard)
$bg = imagecolorallocate($im, 0,0,0); // Background color
for($i<0;$i<100;$i ){
$color_dian = imagecolorallocate($im, rand(0,255),rand(0,255),rand (0,255));
imagesetpixel($im, rand()%100, rand()%30, $color_dian); // Draw points on the artboard
}
$color_font = imagecolorallocate($im, rand(88,255), rand(88,255), rand (100,255)); // Set the color of the color text
$color_line = imagecolorallocate($im, rand(0,255),rand(0,255),rand (0,255)); // Set the color of the color line
imageline($im, rand(1,10), rand(5,13), rand(80,100), rand(5,15), $color_line); // The line starts from the second parameter, the x-axis of the line head, the y-axis, and the end of the x-axis , y-axis, the color assigned
imagestring($im,5,rand(4,60), rand(3,10), $rand ,$color_font); //Write the generated code on the drawing board starting from the second parameter font attributes , the position x-axis, y-axis, random verification code, color displayed on the drawing board
// imagettftext($im, 12, 0, 12, 20, $color_font, 'haha.ttf', "I Ruthless"); Write on the drawing board
header("Content-type:image/jpeg"); // Declare what is to be output
imagejpeg($im); // Output the image in jpeg format to the browser