How can the HTTP protocol affect the way images are displayed in PHP?

The HTTP protocol can affect the way images are displayed in PHP by not sending the correct content type header, which can result in images not being displayed properly in the browser. To solve this issue, you can set the correct content type header for images using the header() function in PHP.

<?php
// Set the content type header for images
header('Content-Type: image/jpeg');

// Output the image
$image = imagecreatefromjpeg('image.jpg');
imagejpeg($image);
imagedestroy($image);
?>