Blame | Letzte Änderung | Log anzeigen | RSS feed
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1"><LINK REL="Start" HREF="index.html"><LINK REL="Contents" HREF="toc.html"><LINK REL="Prev" HREF="412WhatyouwillNOTlearninthischapter.html"><LINK REL="Next" HREF="421UsingtheJpGraphlibrarytosendbackimages.html"><STYLE TYPE="text/css"><!--BODY { font-family: serif }H1 { font-family: sans-serif }H2 { font-family: sans-serif }H3 { font-family: sans-serif }H4 { font-family: sans-serif }H5 { font-family: sans-serif }H6 { font-family: sans-serif }SUB { font-size: smaller }SUP { font-size: smaller }PRE { font-family: monospace }A { text-decoration: none }--></STYLE></HEAD><BODY><A HREF="toc.html">Contents</A><A HREF="412WhatyouwillNOTlearninthischapter.html">Previous</A><A HREF="421UsingtheJpGraphlibrarytosendbackimages.html">Next</A><HR NOSHADE><H2><A NAME="4_2">4.2 How to generate images with PHP</A></H2><P> As a general rule each PHP script which generates an image must bespecified in a separate file which is then called in an HTML <IMG> tag.For example, the following HTML excerpt includes the image generated bythe PHP script in "fig1.php".</P><P><DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB"> </FONT><FONT color="#007700"><</FONT><FONT color="#0000BB">img src</FONT><FONTcolor="#007700">=</FONT><FONT color="#DD0000">"fig1.php" </FONT><FONT color="#0000BB">border</FONT><FONT color="#007700">=</FONT><FONT color="#0000BB">0 align</FONT><FONTcolor="#007700">=</FONT><FONT color="#0000BB">center width</FONT><FONT color="#007700">=</FONT><FONT color="#0000BB">300 height</FONT><FONT color="#007700">=</FONT><FONTcolor="#0000BB">200</FONT><FONT color="#007700">></FONT><FONT color="#0000BB"></FONT></FONT></CODE></DIV></P><P></P><P> Strictly speaking the "align", "width" and "height" are notnecessary but helps the browser position the image correctly before theimage has been fully sent back to the browser.</P><P> The library will automatically generate the necessary headers to besent back to the browser so that it correctly recognize the data streamreceived as an image of either PNG/GIF/JPEG format. The browser canthen correctly decode the image</P><P> Observe that you<STRONG> can't</STRONG> return anything else than animage from the image script. By definition each HTML page (or morecorrectly each HTTP stream) can only consist of one mime type which isdetermined by the header for that particular stream.</P><P> A common mistake is to have a space in the beginning of the imagescript which the HTTP server will send back to the browser. The browsernow assumes that the data coming back from this script is text since ithasn't received an explicit header. When then the image headers getsent back to the browser to forewarn the browser of the forthcomingimage the browser will not like that as it has already assumed the datastream was a text stream. The browser will then give the infamous"Headers already sent error".</P><P> To include several images together with text on a page you need tohave a parent page with several <IMG> tags which each refers to animage script (or the same image script with GET/POST data).</P><HR NOSHADE><A HREF="toc.html">Contents</A><A HREF="412WhatyouwillNOTlearninthischapter.html">Previous</A><A HREF="421UsingtheJpGraphlibrarytosendbackimages.html">Next</A></BODY></HTML>