How can CSS be utilized to improve the formatting and styling of image displays generated by PHP scripts?

When PHP scripts generate image displays, CSS can be utilized to improve the formatting and styling of these images. By applying CSS rules to the HTML output generated by the PHP script, you can control aspects such as image size, alignment, borders, shadows, and more. This allows for a more visually appealing and cohesive design for the image displays.

<?php
// PHP script generating image display
$imageUrl = "path/to/image.jpg";

// Output HTML with CSS styling for image display
echo '<div style="width: 300px; height: 200px; border: 1px solid #ccc; box-shadow: 2px 2px 5px #888; text-align: center;">
          <img src="' . $imageUrl . '" style="max-width: 100%; max-height: 100%; object-fit: cover;">
      </div>';
?>