PHP imagecreatefrompng(file) fails when file is a dynamic image file?

Is it possible to use imagecreatefrompng() with a php file that returns a dynamic png image?


 $IM = imagecreatefrompng('image.php?var=1');

where image.php looks something like:

 // code to generate image
 header("content-type: image/png");
 imagepng ( $OUTPUT );

At the moment I'm getting a "failed to open stream" error - can this be done? If not, are there any quick & easy workarounds? (that don't involve using image.php to save a .png file for the script to detect instead.)




Query parameters ?var=1 work only when requesting a resource through http, not through the file system. To do this, you would have to specify a full URL:

 $IM = imagecreatefrompng('http://localhost/image.php?var=1');

(If your PHP is configured to allow this)

However, the usually much more desirable way would be to include image.php directly and pass var to it using a normal variable. That saves you a http request that, even if made locally, spawns a new PHP process.


 ? Protect a folder by .htaccess RewriteRule to php
 ? Use PHP to Dynamically Add To .htaccess File?
 ? Using htaccess to check file in another directory
 ? Protect files with .htaccess from the outside, while still allowing internal access
 ? how to Protect Php file with the htaccess to protevent external use or a direct use
 ? Re-writing Dynamic URL with .htaccess
 ? Spoof .php as .png in .htaccess?
 ? PHP: Handling Dynamic File Request
 ? How do you add dynamic 'where' clauses to a linq query?
 ? How do you add dynamic 'where' clauses to a linq query?