title: Output images to html using python
body: <p>I have a webpage generated from python that works as it should, using:</p>
  
  <pre><code>print 'Content-type: text/html\n\n'
  print  ""                                 # blank line, end of headers
  print '&lt;link href="default.css" rel="stylesheet" type="text/css" /&gt;'
  print "&lt;html&gt;&lt;head&gt;"
  </code></pre>
  
  <p>I want to add images to this webpage, but when I do this:</p>
  
  <pre><code>sys.stdout.write( "Content-type: image/png\n\n" + file("11.png","rb").read() )
  print 'Content-type: text/html\n\n'
  print  ""                                 # blank line, end of headers
  print '&lt;link href="default.css" rel="stylesheet" type="text/css" /&gt;'
  ...
  </code></pre>
  
  <p>All I get is the image, then if I place the image code below my html/text header all I get is the text from the image, ie:</p>
  
  <pre><code>&lt;Ï#·öÐÎ´ÝZºm]¾|‰k×®]žòåËÛ¶ÃgžyFK–,ÑôéÓU½zuIÒ}÷Ý§&amp;MšH’V¯^­?üð¼1±±±zýõ×%IñññÚºu«*W®¬wß}W.—K3gÎÔÌ™ÿw‹Ú””I’¹w¤¥hdÒd½q÷X•Šˆ²m¿þfïÞ½*]º´éÈs;¥¤¤Ø¿ILLÔˆ#rÊ
  </code></pre>
  
  <p>Also, if I try:</p>
  
  <pre><code>print "&lt;img src='11.png'&gt;"
  </code></pre>
  
  <p>I get a broken image in the browser, and browing directly to the image produces a 500 internal server error, with my apache log saying:</p>
  
  <pre><code>8)Exec format error: exec of './../../11.png' failed Premature end of script headers: 11.png 
  </code></pre>