How can the GD library be used to display images in PHP?

The GD library in PHP can be used to display images by creating a new image resource, loading an existing image file, and outputting the image to the browser. This can be achieved by using functions like imagecreatefromjpeg(), imagecreatefrompng(), and imagejpeg().

// Create a new image resource
$image = imagecreatefromjpeg('example.jpg');

// Output the image to the browser
header('Content-Type: image/jpeg');
imagejpeg($image);

// Free up memory
imagedestroy($image);