Use PHP to write a verification code picture, because the width is dead, so the operation is not very convenient, then try to write flexible, as a callable function.

Source: Internet
Author: User
Tags border color

<?php//Due to the height and width of the captcha image are fixed, not so easy-to-use, change'll be diffic//Declare The following code to the browser is displayed as a pictureheader (' content-type:image/jpeg ');//Width 120$width=120;//Hei Ght 40$height=40;//draws an image that 120*40$img = Imagecreatetruecolor ($width, $height);//Random letters in the Captch A$ele = Array ("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 "); $string =" "; for ($i = 0; $i < 4; $i + +) {$string. = $ele [Rand (0,count ($ele)-1)];} The image ' s background color$colorbg = Imagecolorallocate ($img, Rand (200,255), Rand (200,255), Rand (200,255));//The IM Age ' s Border color$colorborder = Imagecolorallocate ($img, Rand (200,255), Rand (200,255), Rand (200,255));//Font color$ colorstring = Imagecolorallocate ($img, Rand (10,100), Rand (10,100), Rand (10,100));//Fill color to the Imageimagefill ($ IMG, 0, 0, $colorBg);//Draw the Rectangleimagerectangle ($img, 0, 0, $width-1, $height-1, $colorBorder); for ($i = 0; $i <; $i + +) {//Using Stochastic methods to draw Pointsimagesetpixel ($img, RA nd (0, $width-1), rand (0, $height-1), Imagecolorallocate ($img, Rand (100,150), Rand (100,150), Rand (100,150));} Draws a linefor ($i = 0; $i < 3; $i + +) {Imageline ($img, rand (0, $width/2), rand (0, $height/2), Rand ($width/2, $width), R and (0, $height), Imagecolorallocate ($img, Rand (100,150), Rand (100,150), Rand (100,150));} Fontimagettftext ($img, Rand (15,20), Rand ( -5,10), Rand (10,20), Rand (30,35), $colorString, ' Garton. TTF ', $string);//Output Imageimagejpeg ($IMG);//Release the memory being used by the image, and then clear the GRAPHICIM Agedestroy ($img);? >

This code is for novice reference only, if the big God has the opinion, please raise, younger brother grateful

The above code is purely my hand, reproduced please specify!

Use PHP to write a verification code picture, because the width is dead, so the operation is not very convenient, then try to write flexible, as a callable function.

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.