Create a picture
$im = Imagecreatetruecolor (100,30);
Generate color, when the first call to generate a color method, is to generate a background color, default is black
If you want to customize the background color, use the Imagefill function
$BG = Imagecolorallocate ($im, 200,200,200);
Imagefill ($im, 0,0, $BG);
The second call to this method is the ability to generate the text above the picture or the color of other styles
$te = Imagecolorallocate ($im, 0,0,0);
$te 2 = imagecolorallocate ($im, 255,255,255);
Create an interference line, just draw a line
$posLineX 1 = rand (6,30);
$posLineX 2 = rand (30,60);
for ($i =0; $i <5; $i + +) {
$posLinY 1=rand (2,10);
$posLinY 2=rand (11,28);
Imageline ($im, $posLineX 1, $posLinY 1, $posLineX 2, $posLinY 2, $te 2);
$posLineX 1 + = rand (30,60);
$posLineX 2 + = rand (61,98);
}
for ($i =0; $i <90; $i + +) {
$te 3 = imagecolorallocate ($im, Rand (0,255), Rand (0,255), Rand (0,255));
Imagesetpixel ($im, rand (2,100), Rand (2,30), $te 3);
}
Create text on top of a picture
Imagestring ($im, 5,rand (3,70), Rand (3,15), $rand, $te);
$posX = rand (6,45);
for ($i =0; $i <4; $i + +) {
$posY = rand (2,15);
Imagestring ($im, rand (2,5), $posX, $posY, substr ($rand, $i, 1), $te);
$posX + = rand (8,20);
}
To take PHP as a picture output, you must give the file a header declaration
Ob_clean ();
Header ("Content-type:image/jpeg");
Final image generation
Imagejpeg ($im);
The resulting picture can be in the form of JPEG and GIF and PNG