<?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.