i have edited my php.ini for php_gd.dll and apache works fine but when i call <img src="button.php?text"> my page cant draw the image but gives no parse error.

here is my button.php

<?php
Header("Content-type: image/png");
$string=implode($argv," ");
$im = imageCreateFromPng("images/button1.png");
$orange = ImageColorAllocate($im, 220, 210, 60);
$px = (imagesx($im)-7.5*strlen($string))/2;
ImageString($im,3,$px,9,$string,$orange);
ImagePng($im);
ImageDestroy($im);
?>

any suggestions? thanks

    This one got me aswell, i assmued the header for png would be...

    Header("Content-type: image/png");

    but i the browser rejected it, so i tried...

    Header("Content-type: image/jpeg");

    This worked, no doubt someone will tell me im wrong but it worked for me and displayed the png image

    Mark
    www.hdwt.com

      i m afraid that doesnt work for me...any other suggestions?

        Your code looks fine, i would double check this line though

        $px = (imagesx($im)-7.5*strlen($string))/2;

        I was getting something similar when working with sizing it could be that, i don't really know...

        First of all check the GD Library dll was loaded using phpinfo();

        Then check your version of the GD Library supports the png image type because some builds don't support it

        Mark
        www.hdwt.com

          gd is loaded (version 2.0) and png is enabled.

            • [deleted]

            and what is the error that you get?

              Are you calling the script like so

              <img src="button.php?text=<? echo $text; ?>"

              Mark
              www.hdwt.com

                no error, just the image is not displayed in page, in ie i get the box with the red x, just like when an image is not found. can u help?

                  no i am calling it <img src="button.php?text"> . i am still testing it so i just want to display the word "text" on an image...

                    it asks me to open from current location or save...when i choose open from current location it opens imageready but the latter fails to open the file. any ideas?

                      • [deleted]

                      comment out the image-headers for debugging, see what the script says.

                        button.php :
                        <?
                        //Header("Content-type: image/png ");
                        $string=implode($argv," ");
                        $im = imageCreateFromPng("images/button1.png");
                        $orange = ImageColorAllocate($im, 220, 210, 60);
                        $px = (imagesx($im)-7.5*strlen($string))/2;
                        ImageString($im,3,$px,9,$string,$orange);
                        ImagePng($im);
                        ImageDestroy($im);
                        ?>

                        http://localhost/button.php?text gives:

                        Warning: imagecreatefrompng: Unable to open 'images/button1.png' for reading in c:\foxserv\www\button.php on line 4

                        Warning: Supplied argument is not a valid Image resource in c:\foxserv\www\button.php on line 5

                        Warning: Supplied argument is not a valid Image resource in c:\foxserv\www\button.php on line 6

                        Warning: Supplied argument is not a valid Image resource in c:\foxserv\www\button.php on line 7

                        Warning: Supplied argument is not a valid Image resource in c:\foxserv\www\button.php on line 8

                        Warning: Supplied argument is not a valid Image resource in c:\foxserv\www\button.php on line 9

                          • [deleted]

                          problem solved I guess? 🙂

                            my quess is that there is a problem with the gd library cause the code is from the manual. what could i do if phpinfo says that gd library is ok?

                              • [deleted]

                              Well, my guess is that you are trying to access a file that does not exist, or that has a different name or location.

                                Write a Reply...