If you need to call imagepng() multiple times (for example, when you want to send it to the browser, but also to a disk cache), write your image to a file first, THEN call readfile() on it.
PHP internally works with a temporary file when sending the image to the browser, so you'll gain nothing by calling imagepng() twice.