<?php One: GD function library1. Function: Imagecreate (width,height) creates a color palette-based Image Imagecreatetruecolor (width,height) to create a true-color-based image header ( /c2>"content-type:image/Picture Format"); Image format: gif jpeg PNG imagegif (image) output image Imagedestroy (image) destroys image imagestring (image, Font, x, Y,string, color) writes the string imagecolorallocate (image, red, green, blue) to assign a color imagettftext (image, //ImageSize//Text size unit pxAngle//angle of inclinationX//the coordinates of the beginning of the textY//the coordinates of the beginning of the textColor//ColorFontfile,//the location of the TTF fileText//text content) imagefilledrectangle (image, x1, y1, x2, y2, color) draw a rectangle Imagesetpixel (image, X, y, color) Draw individual pixel points imageline (image, x1, y1, x2, y2, color) draw a segment?>
Verification Code Case:
<?Phpheader ("Content-type:image/gif");//Verification Code width is high$width =" Max"; $height=" -";//Create a canvas$image =Imagecreatetruecolor ($width, $height);//Assigning Colors$color = Imagecolorallocate ($image,255,255,255);//text color$sizeColor = Imagecolorallocate ($image, Mt_rand (0,255), Mt_rand (0,255), Mt_rand (0,255));//Fill CanvasImagefilledrectangle ($image,0,0, Max, -, $color);//Verification Code Text$num ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $checkStr=NULL;//number of digits of the verification code for($i =0; $i <4; $i + +) {$checkStr= $checkStr. $num [Rand (0, *)];}//writing textImagettftext ($image, -, Mt_rand (-5,5), -, -, $sizeColor,"Segoeprb.ttf", $CHECKSTR); //draw a noise point for($i =0; $i < -; $i + +) {imagesetpixel ($image, Mt_rand (0, Max), Mt_rand (0, -), $sizeColor);}//Draw Interference Lines for($i =0; $i <4; $i + +) {imageline ($image, Mt_rand (0, Max), Mt_rand (0, -), Mt_rand (0, Max), Mt_rand (0, -), $sizeColor);}//Output Imageimagegif ($image);//Destroying ImagesImagedestroy ($image);?>
PHP base------GD Library drawing verification Code