How can headers be properly sent in PHP to ensure correct image display?

When displaying images in PHP, it is important to send the correct headers to ensure that the image is displayed correctly in the browser. This can be done by setting the Content-Type header to the appropriate image type (e.g., image/jpeg, image/png) before outputting the image data. Failure to set the correct headers may result in the image not displaying properly or at all.

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

// Output the image data
$image = file_get_contents('path/to/image.jpg');
echo $image;
?>