What are some best practices for loading and outputting images in PHP?

When loading and outputting images in PHP, it is important to use proper headers to ensure the image is displayed correctly in the browser. One common best practice is to use the "image/jpeg" or "image/png" content type headers when outputting JPEG or PNG images respectively. Additionally, it is recommended to use the appropriate image functions in PHP to load and output images securely.

// Load and output a JPEG image
$image = imagecreatefromjpeg('image.jpg');
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);