How can PHP's graphic functions be utilized to create and display images?
To create and display images using PHP's graphic functions, you can use the GD library which provides a set of functions for image creation and manipulation. You can start by creating a new image using `imagecreate()` or `imagecreatetruecolor()`, then use functions like `imagecolorallocate()` to define colors, `imagesetpixel()` to set individual pixels, and `imagefilledrectangle()` to draw shapes. Finally, you can output the image using `imagepng()`, `imagejpeg()`, or `imagegif()`.
// Create a new image
$image = imagecreatetruecolor(200, 200);
// Define colors
$red = imagecolorallocate($image, 255, 0, 0);
$blue = imagecolorallocate($image, 0, 0, 255);
// Draw shapes
imagefilledrectangle($image, 50, 50, 150, 150, $red);
imagefilledrectangle($image, 100, 100, 150, 150, $blue);
// Output the image
header('Content-Type: image/png');
imagepng($image);
// Free up memory
imagedestroy($image);