在IE中提供静态图像会产生Quirks模式

Following the approach mentioned here I can successfully serve up png, gif, or whatever images I want but since I don't have any control over the <!DOCTYPE> of the page (that I know of) IE9 (and presumably others) decide that the "Document Mode" is "Quirks" as the default.

IE successfully displays the image (just a slight shadow around the edge of the document provides any clue of a problem) so maybe I should be content and disregard the dreaded quirks mode status that is given to the page created in this way.

My approach is similar to the one in the above answer:

# Other processing that is not output / echoed
# <-- Can something else be sent here to calm IE down?
header('Content-Type: image/png');
readfile($imagePath);

This approach results in an HTML document that looks like this according to IE's Developer Tools:

<html>
    <head>
        <title></title>
    <body>
        <img src="theUrlOfThePage" />

Is there a way to tweak the DOCTYPE (or lack thereof) without getting in the way of the header that is sent nor the image I want to output? My attempts to pass the DOCTYPE at various stages of the above process just broke the ability to display the image properly.

Use a header template which includes the doctype:

<?php
echo <<<HEADER
<!doctype html>
  <html>
     <body>

HEADER;
?>

and a footer template which ends the file:

<?php
echo <<<FOOTER
  </body>
</html>
FOOTER;
?>

In the main file, include both as well as the existing content:

<?php
include('header.php')
include('content.php')
include('footer.php')
?>

Use output buffering to cache the output string internally and send it to the user in one shot. In long-running scripts, you will also want to flush the output buffer periodically so that some feedback is sent to the HTTP client. This can be done with ob_end_flush(). This function also turns off output buffering, so you might want to call ob_start() again immediately after the flush.

The Link header would be useful, but only in Firefox: