What are common pitfalls when trying to display images in PHP, especially when using GD-Lib?

Common pitfalls when trying to display images in PHP, especially when using GD-Lib, include not setting the correct content type header before outputting the image, not properly handling errors or exceptions, and not checking if the GD extension is installed on the server. To solve these issues, make sure to set the correct content type header using `header('Content-Type: image/jpeg');`, handle errors or exceptions using try-catch blocks, and check if the GD extension is installed using `extension_loaded('gd')`.

<?php
// Check if GD extension is installed
if (!extension_loaded('gd')) {
    die('GD extension is not installed on the server.');
}

// Set the correct content type header
header('Content-Type: image/jpeg');

// Display the image using GD-Lib functions
$image = imagecreatefromjpeg('image.jpg');
imagejpeg($image);
imagedestroy($image);
?>