Use the method suggested above. As far as I know there is no other way. The way this works is that in PHP you can set the headers, which define what sort of file type it will look like to the browser. So in the above script, you set the headers to JPG or PNG and the browser then things it is an image even though it is in fact a PHP script, which creates the image. The problem is however, that if you give it the png extension it will automatically be treated as an image, the server will not try to execute it and run the code, it will simply use the actual code as image data, which wouldn´t work.