Example of the PHP function for generating image verification Codes,

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.