| 1 |
lars |
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
|
|
2 |
<HTML>
|
|
|
3 |
<HEAD>
|
|
|
4 |
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=iso-iso-8859-1">
|
|
|
5 |
<LINK REL="Start" HREF="index.html">
|
|
|
6 |
<LINK REL="Contents" HREF="toc.html">
|
|
|
7 |
<LINK REL="Prev" HREF="412WhatyouwillNOTlearninthischapter.html">
|
|
|
8 |
<LINK REL="Next" HREF="421UsingtheJpGraphlibrarytosendbackimages.html">
|
|
|
9 |
<STYLE TYPE="text/css"><!--
|
|
|
10 |
BODY { font-family: serif }
|
|
|
11 |
H1 { font-family: sans-serif }
|
|
|
12 |
H2 { font-family: sans-serif }
|
|
|
13 |
H3 { font-family: sans-serif }
|
|
|
14 |
H4 { font-family: sans-serif }
|
|
|
15 |
H5 { font-family: sans-serif }
|
|
|
16 |
H6 { font-family: sans-serif }
|
|
|
17 |
SUB { font-size: smaller }
|
|
|
18 |
SUP { font-size: smaller }
|
|
|
19 |
PRE { font-family: monospace }
|
|
|
20 |
A { text-decoration: none }
|
|
|
21 |
--></STYLE>
|
|
|
22 |
</HEAD>
|
|
|
23 |
<BODY>
|
|
|
24 |
<A HREF="toc.html">Contents</A>
|
|
|
25 |
<A HREF="412WhatyouwillNOTlearninthischapter.html">Previous</A>
|
|
|
26 |
<A HREF="421UsingtheJpGraphlibrarytosendbackimages.html">Next</A>
|
|
|
27 |
<HR NOSHADE>
|
|
|
28 |
<H2><A NAME="4_2">4.2 How to generate images with PHP</A></H2>
|
|
|
29 |
<P> As a general rule each PHP script which generates an image must be
|
|
|
30 |
specified in a separate file which is then called in an HTML <IMG> tag.
|
|
|
31 |
For example, the following HTML excerpt includes the image generated by
|
|
|
32 |
the PHP script in "fig1.php".</P>
|
|
|
33 |
<P><DIV class="phpscript"><CODE><FONT color="#000000"> <FONT color="#0000BB">
|
|
|
34 |
</FONT><FONT color="#007700"><</FONT><FONT color="#0000BB">img src</FONT><FONT
|
|
|
35 |
color="#007700">=</FONT><FONT color="#DD0000">"fig1.php" </FONT><FONT color="#0000BB">
|
|
|
36 |
border</FONT><FONT color="#007700">=</FONT><FONT color="#0000BB">0 align</FONT><FONT
|
|
|
37 |
color="#007700">=</FONT><FONT color="#0000BB">center width</FONT><FONT color="#007700">
|
|
|
38 |
=</FONT><FONT color="#0000BB">300 height</FONT><FONT color="#007700">=</FONT><FONT
|
|
|
39 |
color="#0000BB">200</FONT><FONT color="#007700">></FONT><FONT color="#0000BB">
|
|
|
40 |
</FONT></FONT></CODE></DIV></P>
|
|
|
41 |
<P></P>
|
|
|
42 |
<P> Strictly speaking the "align", "width" and "height" are not
|
|
|
43 |
necessary but helps the browser position the image correctly before the
|
|
|
44 |
image has been fully sent back to the browser.</P>
|
|
|
45 |
<P> The library will automatically generate the necessary headers to be
|
|
|
46 |
sent back to the browser so that it correctly recognize the data stream
|
|
|
47 |
received as an image of either PNG/GIF/JPEG format. The browser can
|
|
|
48 |
then correctly decode the image</P>
|
|
|
49 |
<P> Observe that you<STRONG> can't</STRONG> return anything else than an
|
|
|
50 |
image from the image script. By definition each HTML page (or more
|
|
|
51 |
correctly each HTTP stream) can only consist of one mime type which is
|
|
|
52 |
determined by the header for that particular stream.</P>
|
|
|
53 |
<P> A common mistake is to have a space in the beginning of the image
|
|
|
54 |
script which the HTTP server will send back to the browser. The browser
|
|
|
55 |
now assumes that the data coming back from this script is text since it
|
|
|
56 |
hasn't received an explicit header. When then the image headers get
|
|
|
57 |
sent back to the browser to forewarn the browser of the forthcoming
|
|
|
58 |
image the browser will not like that as it has already assumed the data
|
|
|
59 |
stream was a text stream. The browser will then give the infamous
|
|
|
60 |
"Headers already sent error".</P>
|
|
|
61 |
<P> To include several images together with text on a page you need to
|
|
|
62 |
have a parent page with several <IMG> tags which each refers to an
|
|
|
63 |
image script (or the same image script with GET/POST data).</P>
|
|
|
64 |
<HR NOSHADE>
|
|
|
65 |
<A HREF="toc.html">Contents</A>
|
|
|
66 |
<A HREF="412WhatyouwillNOTlearninthischapter.html">Previous</A>
|
|
|
67 |
<A HREF="421UsingtheJpGraphlibrarytosendbackimages.html">Next</A>
|
|
|
68 |
</BODY>
|
|
|
69 |
</HTML>
|