Home >Backend Development >PHP Tutorial >php5 image verification code implementation code_PHP tutorial
GD library function
1, imagecreatetruecolor ----- Create a true color image
imagecreatetruecolor(int x_size, int y_size) //x represents width, y represents height
2, imagecolorallocate is a picture Image allocation color (palette)
imagecolorallocate(resource image,int red,int green,int blue)//red, green, blue----three primary colors
3, imagestring drawing function
iamgestring( resource image, font, int x, int y, content, color);
4, output function
The header of php is an action that defines the header. PHP5 supports 3 types:
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
Example: header("Content-type:image/jpeg")
There are corresponding image types in the GD library
imagejpeg(), imagegif(), imagepang()
5, imageline line drawing function
iamgeline(resource image,int x1,int y1,int x2,int y2,int color);
image ---picture
x1 ---starting coordinates
y1
x2 ---End point coordinates
y2
6, imagesetpixel drawing point function
imagesetpixel(resource image, int x, int y, int color)
7, imagettftext with font The writing function
imagettftext(resource image, float size, float angle, int x, int y, int color, string fontfile, string text)
8, the method of inserting Chinese PHP verification code
iconv( "gb2312","utf-8","string"); //First convert the text into utf-8 format
9, random function
1, rand([int min,int max]) //rand(1,4) generates a number from 1 to 4
2, dechex (decimal number) //Convert to hexadecimal
Steps for verification code:
Generate random number--Create Picture--random number written as picture--saved in session
Enter verification code example
gdchek.php