Example of the PHP function for generating image verification Codes,
This example describes how to generate an image verification code in PHP. We will share this with you for your reference. The details are as follows:
Only the random function is used to generate images. The entire verification process is not introduced.
The Code is as follows:
<?php/** * Created by JetBrains PhpStorm. * User: lee * To change this template use File | Settings | File Templates. */header("content-type:image/png");$validateLength=4;$strToDraw="";$chars=[ "0","1","2","3","4", "5","6","7","8","9", "a","b","c","d","e","f","g", "h","i","j","k","l","m","n", "o","p","q","r","s","t", "u","v","w","x","y","z", "A","B","C","D","E","F","G", "H","I","J","K","L","M","N", "O","P","Q","R","S","T", "U","V","W","X","Y","Z"];$imgW=80;$imgH=25;$imgRes=imagecreate($imgW,$imgH);$imgColor=imagecolorallocate($imgRes,255,255,100);$color=imagecolorallocate($imgRes,0,0,0);for($i=0;$i<$validateLength;$i++){ $rand=rand(1,58); $strToDraw=$strToDraw." ".$chars[$rand];}imagestring($imgRes,5,0,5,$strToDraw,$color);for($i=0;$i<100;$i++){ imagesetpixel($imgRes,rand(0,$imgW),rand(0,$imgH),$color);}imagepng($imgRes);imagedestroy($imgRes);
The running effect is as follows:
PS: Here are some useful image processing tools for your reference:
Online image conversion BASE64 tool:
Http://tools.jb51.net/transcoding/img2base64
ICO icon generation tool:
Http://tools.jb51.net/aideddesign/ico_img
Online Email icon creation tools:
Http://tools.jb51.net/email/emaillogo
Online image format conversion (jpg/bmp/gif/png) tool:
Http://tools.jb51.net/aideddesign/picext