PHP Verification Code Drawing

Source: Internet
Author: User

<?php

/* Set Artboard size */

$width = 130;

$height = 60;

/* Create a new True color image */

$img = Imagecreatetruecolor ($width, $height);

/* Predefined color value range */

$ranColor = Imagecolorallocate ($img, Rand (0,255), Rand (0,255), Rand (0,255));

$white = Imagecolorallocate ($img, 255,255,255);

Draw a rectangle with the same capitalization overrides the default background (black) Universal White

Imagefilledrectangle ($img, 0,0,130,60, $white);

Create an array of characters to be drawn

$str = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";   

$str _array = "";

for ($i = 0; $i < 5; $i + +) {//control requires several characters

$str _array = $str _array. $str [Rand (0,strlen ($STR)-1)];

}

/* Custom Font tilt */

Imagettftext ($img, 30,rand ( -7,7), 0,50, $ranColor, ' Calibri.ttf ', $str _array);

/* Randomly draw snowflakes */

for ($i = 0; $i < $i + +) {

Imagesetpixel ($img, Rand (0,130), Rand (0,60), $ranColor);

}

/* Set line width */

Imagesetthickness ($img, 2);

/* Random Dash */

for ($m =0; $m <5; $m + +) {

Imageline ($img, Rand (0,130), Rand (0,60), Rand (0,130), Rand (0,60), $ranColor);

}

Header (' content-type:image/gif ');

/* Output images to a browser or file in GIF format */

Imagegif ($IMG);

/* Destroy image Release Memory */imagedestroy ($IMG);

?>

PHP Verification Code Drawing

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.