I have read two articles over the PHP site over the past two days. Article First, "using PHP to implement the verification code function" and "using the dot method in PHP to" Draw "Chinese" suddenly aroused great interest in the PHP drawing function.
PHP's drawing function is much more powerful and simple than ASP, as I personally think.
PHP drawing requires the installation of the GD library first, and the GD library is more than 1.6 and does not support generating GIF images. Generally, php4.0 and above all come with the GD library. For the software environment required for drawing, if it is not the focus of this article, you will not be tired of it. You can refer to other materials.
1. Start to draw English letters and numbers
Header ("Content-Type: image/GIF"); // HTTP header, indicating the meaning of the image
$ String = "test1234"; // string to be drawn
$ Im = imagecreate (100,100); // create a 100*100 canvas. If you have used the drawing software, you should be familiar with the word.
$ Black = imagecolorallocate ($ im, 0, 0, 0); // background color of the canvas
$ White = imagecolorallocate ($ im, 255,255,255); // set white
$ Gray = imagecolorallocate ($ im, 200,200,200); // set gray
Imagestring ($ im, 5, 10, 30, $ string, $ gray); // draw gray characters on the IM canvas (10, 30)
// Add interference pixel points
For ($ I = 1; $ I
For ($ j = 1; $ J
Imagesetpixel ($ im, Rand () % 100, Rand () % 100, $ white );
}
}
Imagepng ($ IM); // output the image in PNG format
Imagedestroy ($ IM); // clear the image memory resources
This is just an introduction to drawing, familiar with some basic functions of drawing.
ProgramIt runs normally on my computer.
For example, you can change $ string to a random number. :) It is also a simple verification code.
Imagecolortransparent this function is used to set the transparent color, very useful :) very good Oh ~~