Unable to load dynamic image into browser

"Marshintprop" <[email protected]> Mon, 24 Dec 2012 14:32:48 -0600
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
This is a multipart message in MIME format.

--===============0634147477==
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_0032_01CDE1E3.8CD4BB30"
Content-Language: en-us

This is a multipart message in MIME format.

------=_NextPart_000_0032_01CDE1E3.8CD4BB30
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

I do not seem to have success in generating a dynamic image into Internet
Explorer through CGI.  If I save the file and then load it, it works but
when I try to keep the generated image dynamic.  I am using Python 2.6.5 and
the corresponding PIL library.

 

f = cStringIO.StringIO()

img.save(f, "PNG")

 

print "Content-type: image/png\n"

f.seek(0)

print f.read()

 

The above will just generate a screen filled with ascii characters and
symbols.  I have also tried JPEG to no avail.

 

Below generates a blank image:

 

sys.stdout.write('Status: 200 OK\r\n')

sys.stdout.write('Content-type: image/png\r\n\n')

sys.stdout.write('%s' % f.getvalue())

sys.stdout.write('\r\n')

 

Can someone point out my error here?  Writing to file in a cgi environment
is not a great thing to be doing.  Img.sav('test.png') is valid.


------=_NextPart_000_0032_01CDE1E3.8CD4BB30
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 14 =
(filtered medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
pre
	{mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted";
	font-family:"Courier New";}
span.pystring1
	{mso-style-name:py_string1;
	color:green;}
span.pykeyword1
	{mso-style-name:py_keyword1;
	color:#0000C0;
	font-weight:bold;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri","sans-serif";}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal>I do not =
seem to have success in generating a dynamic image into Internet =
Explorer through CGI.&nbsp; If I save the file and then load it, it =
works but when I try to keep the generated image dynamic&#8230;&nbsp; I =
am using Python 2.6.5 and the corresponding PIL =
library.<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal style=3D'background:#F3F3F3'><span =
style=3D'font-size:10.0pt;font-family:"Courier New"'>f =3D =
cStringIO.StringIO()<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:#F3F3F3'><span =
style=3D'font-size:10.0pt;font-family:"Courier New"'>img.save(f, <span =
style=3D'color:green'>&quot;PNG&quot;</span>)<o:p></o:p></span></p><p =
class=3DMsoNormal style=3D'background:#F3F3F3'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal =
style=3D'background:#F3F3F3'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#0000C0'>print</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New"'> <span =
style=3D'color:green'>&quot;Content-type: =
image/png\n&quot;</span><o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:#F3F3F3'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'>f.seek(0)<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:#F3F3F3'><b><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#0000C0'>print</span></b><span =
style=3D'font-size:10.0pt;font-family:"Courier New"'> =
f.read()<o:p></o:p></span></p><p class=3DMsoNormal =
style=3D'background:#F3F3F3'><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal>The above will =
just generate a screen filled with ascii characters and symbols.&nbsp; I =
have also tried JPEG to no avail.<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>Below =
generates a blank image:<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
class=3DMsoNormal>sys.stdout.write('Status: 200 =
OK\r\n')<o:p></o:p></p><p =
class=3DMsoNormal>sys.stdout.write('Content-type: =
image/png\r\n\n')<o:p></o:p></p><p =
class=3DMsoNormal>sys.stdout.write('%s' % f.getvalue())<o:p></o:p></p><p =
class=3DMsoNormal>sys.stdout.write('\r\n')<o:p></o:p></p><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal>Can someone =
point out my error here?&nbsp; Writing to file in a cgi environment is =
not a great thing to be doing.&nbsp; Img.sav(&#8216;test.png&#8217;) is =
valid.<o:p></o:p></p></div></body></html>
------=_NextPart_000_0032_01CDE1E3.8CD4BB30--


--===============0634147477==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig

--===============0634147477==--