Results 1 to 4 of 4

Thread: ImageCreateFromPNG( "myImage.php" )

  1. #1
    Join Date
    Apr 2009

    ImageCreateFromPNG( "myImage.php" )

    I'm trying to use ImageCreateFromPNG to open a dynamic image file created by another PHP document. it looks like this:

    test.php :
    <? (...) $my_image = ImageCreateFromPNG("image.php"); (...)?>
    image.php :
    <? header("Content-type: image/png"); (...) imagepng($im); ImageDestroy($im); ?>
    The "image.php" file works properly when displayed in a browser,
    yet "test.php" says that it "is not a valid PNG file" when I'm trying to access it via ImageCreateFromPNG.

    am I missing something?

  2. #2
    Join Date
    Feb 2003
    Michigan, USA
    That function is trying to open the PHP file, and isn't running that PHP file through PHP to get the output. This will probably be a three step process:

    1) Use fopen and pass it a URL to the script.

    2) Save the resulting image as a resource handle.

    3) Create a PNG file using the ImageCreateFromPNG() function.

    The best solution would be to move functionality common to creating images to another file that both image.php and your current script can use. That way you won't need to open an HTTP connection just to create and save an image on the same server. Then the process would be:

    1) Create the image

    2) Save the resulting image as a resource handle.

    3) Create a PNG file using the ImageCreateFromPNG() function.

    This should bypass the inefficiencies of HTTP connections.

  3. #3
    Join Date
    Sep 2006
    Bucharest, RO
    That is wrong. When you are doing that, PHP is trying to open "image.php" just like when you open it to edit its contents (the file is parsed and run by PHP to generate an image only when it's requested over the network, i.e. http://example.com/image.php). You have two options:
    1. Use imageCreateFromPng('http://example.com/image.php');, but this is bad.
    2. Simply include the image.php file.

  4. #4
    Join Date
    Apr 2009
    thanks for your answers.

    I have solved the problem by including the functionality of the image.php file into my actual script.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles