Create a new canvas and create a true-color blank picture through the imagecreatetruecolor function
$img = imagecreatetruecolor(100,100);
For the color used by the brush, it needs to be allocated through the imagecolorallocate function, and the RGB color value is set through parameters To determine the color of the brush
$red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
Call the line segment function imageline to draw the line, and finally get the line by specifying the starting point and end point.
imageline($img, 0,0,100,100,$red);
Image output through header, imagepng
header("content-type: image/png");
imagepng($img);
Call imagedestroy to release the memory occupied by the image
imagedestroy($img);
Save the drawn image to the file by specifying the file name through the imagepng function
imagepng($image,'line.png');
The above has introduced the use of the GD library, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.