Home >Backend Development >PHP Tutorial >Example of making PHP image verification code
Method 2, defined as a private function.
Method 3 , use random seeds to generate PHP verification codes.
Method 4,
Then let’s get to the focus of this article: PHP GD library: (Provides a series of IPIs for image processing functions to generate image processing images) Enable the GD library in php: In the php.ini configuration file, remove the ";" in ";extension=php_gd2.dll"; Introduction to some GD library functions: 1.imagecreatetruecolor(int x_size,int Y_size) Create a new true color image 2.imagecolorallocate(resource image,int red,int green,int blue) assigns color to an image, three primary colors 3.imagestring(resource,font,int x,int y,content,color) drawing function 4.header("Content-type:image/jpeg") The header of the output function php is an action that defines the header. php5 supports 3 of them. Type: 1, Content-type: xxxx/yyyy 2, Location: xxxx:yyyy/zzzz 3, Status: nnn xxxxxx xxxx/yyyy indicates the type of content file such as: image/gif image/jpeg image/png imagejpeg(), imagegif (),imagepang() 5.iamgeline(resource image,int x1,int y1,int x2,int y2,int color); Line drawing function, (int x, int y) starting coordinates 6.imagesetpixel(resource image,int x,int y,int color) drawing point function 7.imagettftext(resource image,float size,float angle,int x,int y,int color,string fontfile,string text) with font writing function 8.iconv("gb2312","utf-8","string "); //First, convert the text into UTF-8 format. How to insert the PHP verification code into Chinese. Here you can refer to the method of generating PHP Chinese verification code. Example 1, randomly generate numbers and letter codes:
Example 2, draw interference line code for the picture:
Example 3, code to draw interference points on pictures:
Example 4, write text into image code:
0: the inclination of the font, "simhei.ttf": the font style, usually placed at the root Under the directory; This completes the entire production process of PHP image verification code. The script editor hopes that this article will be helpful to use the gd library to generate PHP verification code. |