Problems outputting an image over http using Python
<p>I'm trying to load an image file from my local disk and output it over http when the script is accessed on my webserver via cgi.</p>

<p>For example I want <a href="http://example.com/getimage.py?imageid=foo" rel="nofollow">http://example.com/getimage.py?imageid=foo</a> to return the corresponding image. Just opening the file and printing imgfile.read() after the appropriate content headers, however, causes the image to be scrambled. Clearly the output isn't right, but I have no idea why.</p>

<p>What would be the best way to do this, using the built-in modules of 2.6?</p>

<p>Edit:</p>

<p>The code essentially boils down to:</p>

<pre><code>imgFile=open(fileName,"rb")
print "Content-type: image/jpeg"
print
print imgFile.read()
imgFile.close()
</code></pre>

<p>It outputs <em>an</em> image, just one that seems to be random data.</p>
