I found instructions for this at New York PHP. You code your php file with the calls to GD, etc. Then call the php file (with parameters to control it) like an image from the page it is used in.
Introduction to PHP Image Functions
In the above presentation, you create a php file "simplepng.php".
You then choose a color (0A2F90) and call this file from your web page as if it was an image: