The example in this article tells you how to draw a straight line in PHP. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
<?php
1. Create Canvas
$im = Imagecreatetruecolor (300,200);//Create a new true color image, the default background is black, and return the image identifier. Another function, imagecreate, is deprecated.
2, to draw the desired image
$red = Imagecolorallocate ($im, 255,0,0);//Create a color to use
Imageline ($im, 30,30,240,140, $red);//Draw a straight line. Parameter Description: 30,30 represents the start coordinate, 240,140 indicates the endpoint coordinates
3. Output image
Header ("Content-type:image/png");
Imagepng ($im);//output to page. If there is a second argument [, $filename], the image is saved
4, destroy the image, free memory
Imagedestroy ($im);
?>
I hope this article will help you with your PHP program design.