Generate simple verification codes based on PHP, and generate simple verification codes based on PHP.
If you don't talk much about it, paste the Code directly. The specific code is as follows:
For ($ I = 0; $ I <5; $ I ++) {$ rand. = dechex (rand (); // a random number is generated in hexadecimal notation 1-F.} $ im = imagecreatetruecolor (); // The verification code size (canvas) $ bg = imagecolorallocate ($ im, 100, 0); // background color for ($ I <0; $ I <; $ I ++) {$ color_dian = imagecolorallocate ($ im, rand (0,255), rand (0,255), rand (0,255); imagesetpixel ($ im, rand () % 100, rand () % 30, $ color_dian); // draw a vertex on the canvas} $ 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 line imageline ($ im, rand (80,100), rand (), rand (), $ color_line ); // The line starts from the second parameter. The X axis and Y axis of the line header, the end X axis, the Y axis, the assigned color imagestring ($ im, 5, rand (), rand ), $ rand, $ color_font ); // write the generated code on the canvas. The font attributes start from the second parameter, the position X axis, Y axis, Random verification code, and color displayed on the canvas. // imagettftext ($ im, 12, 0, 12, 20, $ color_font, 'haha. ttf', ""); write the header ("Content-type: image/jpeg") on the canvas "); // declare what you want to output imagejpeg ($ im); // output the image to the browser in jpeg format
The above code is a simple verification code generated based on PHP introduced by the small Editor. The code is accompanied by a comment. If you have any questions during the reference process, please leave a message to me. The small editor will reply to you in time.