It is also possible to generate images directly using the command line version of PHP. This works the same way as the normal "through the browser" generation with the exception that no HTTP headers will be generated. Only the binary image data.
Please make sure that you run the command line version of PHP (cli). Using the CGI SAPI version will not work since then the HTTP headers will be generated. Note: If the CGI version is used the generation of headers may be suppressed by the '-q' option.
You can easily check the version installed by running
you should then get a response with something like
PHP 4.3.8 (cli) (built: Aug 29 2004 22:48:10) Copyright (c) 1997-2004 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
The important thing here is the
marker. The JpGraph library check from what SAPI API it is invoked from and adjusts the header generation accordingly.
If all the above requirements are met then images can be generated directly on the command line and stored in a suitable file. For example by
$> php myimage.php > image.png
Please note that the file extension on the image file must match the format in which the image is generated.