PHP Image Verification Code generation sample code

Source: Internet
Author: User
This article mainly for you in detail the PHP image verification code generation code, with a certain reference value, interested in small partners can refer to

The example of this article for everyone to share a PHP package generated image verification code, for your reference, the specific content as follows

One, the code

Index: Php

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

Testcode.php

<?php class testcode{//creates a Testcode private $width;    Private $height;    Private $str;    Private $im;       Private $strColor;     function construct ($width, $height) {$this->width= $width;     $this->height= $height;     $this->str=$_get[' code ';    $this->createimage (); } function CreateImage () {$this->im=imagecreate ($this->width, $this->height);//Create Canvas imagecolorallocate ( $this->im,200,200,200);//Add a color for the canvas for ($i =0; $i <4; $i + +) {//loop output four digits $this->strcolor=imagecolorallocate ($thi      S->im,rand (0,100), Rand (0,100), Rand (0,100)); Imagestring ($this->im,rand (3,5), $this->width/4* $i +rand (5,10), rand (2,5), $this->str[$i], $this-     Strcolor); } for ($i =0; $i <200; $i + +) {//Loop output 200 dots $this->strcolor=imagecolorallocate ($this->im,rand (0,255), Rand (0,2      ), Rand (0,255));     Imagesetpixel ($this->im,rand (0, $this->width), rand (0, $this->height), $this->strcolor); }} function Show () {//Header(' content-type:image/png ');//define output as Image type Imagepng ($this->im);//Generate Image Imagedestroy ($this->im);//Destroy image to free memory} } $image =new Testcode (80,20);//Instantiate class as Object $image->show ();//Call Function?>

ii. Results of Operation

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.