JpGraph:图片显示的方法和注意事项
================================
作者:Wandering
请先看一下JpGraph手册中是如何描述的:
4.2 How to generate images with PHP
As a general rule each PHP script which generates an image must be specified in a separate file which is then called in an HTML tag. For example, the following HTML excerpt includes the image generated by the PHP script in "fig1.php".
Strictly speaking the "align", "width" and "height" are not necessary but helps the browser position the image correctly before the image has been fully sent back to the browser.
The library will automatically generate the necessary headers to be sent back to the browser so that it correctly recognize the data stream received as an image of either PNG/GIF/JPEG format. The browser can then correctly decode the image
Observe that you can't return anything else than an image from the image script. By definition each HTML page (or more correctly each HTTP stream) can only consist of one mime type which is determined by the header for that particular stream.
A common mistake is to have a space in the beginning of the image script which the HTTP server will send back to the browser. The browser now assumes that the data coming back from this script is text since it hasn't received an explicit header. When then the image headers get sent back to the browser to forewarn the browser of the forthcoming image the browser will not like that as it has already assumed the data stream was a text stream. The browser will then give the infamous "Headers already sent error".
To include several images together with text on a page you need to have a parent page with several tags which each refers to an image script (or the same image script with GET/POST data).
OK,注意事项是:
1、生成图片的php文件只能产生和返回图像,在JpGraph生成图像的代码之前不要有任何html输出,切记~
2、在HTML中显示JpGraph PHP文件产生图像的唯一方法是使用标志,使用时设置src属性为php文件。
3、在同一HTML文件中显示多个JpGraph图像的方法就是使用多个标志。