1

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

eg.

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

where image.php looks something like:

<?php
 // 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.)

Thanks,

Chris

7
  • there is no such file, silly. Commented Jan 31, 2011 at 16:05
  • 3
    @Col. Shrapnel Oh dude, please help the guy out by giving a detailed answer! Commented Jan 31, 2011 at 16:06
  • why so complex structure? ever tried to create an image ONCE, not thousand times, passing it from one script to another? Commented Jan 31, 2011 at 16:07
  • My poor boy, to get a detailed answer one have to ask a detailed question! And sensible one. Commented Jan 31, 2011 at 16:08
  • 2
    If you have nothing constructive or helpful to say, you are usually better off keeping your mouth shut. Commented Jan 31, 2011 at 16:14

1 Answer 1

4

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:

<?php
 $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.

Sign up to request clarification or add additional context in comments.

1 Comment

Which will only work if the php.ini setting allow_url_fopen is enabled. php.net/manual/en/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.