How could the PHP code be optimized for better performance when retrieving and displaying images from a database?

When retrieving and displaying images from a database in PHP, it is important to optimize the code for better performance. One way to do this is by storing the images in the file system instead of the database and only storing the file path in the database. This reduces the load on the database and speeds up the retrieval process.

// Retrieve image file path from the database
$imagePath = "path/to/image.jpg";

// Display the image
echo '<img src="' . $imagePath . '" alt="Image">';