Hello,

I'm trying to display a very simple thing using GDlib...

imagepng doesn't work but imagejpeg does...

Link:
http://www.hpiracing.com/gdtest2.php

Code for imagepng:

$im = imagecreate ( 250, 100) 
    or die ("Cannot create a new GD image."); 
$background_color = imagecolorallocate ($im, 255, 255, 255); 
$text_color = imagecolorallocate ($im, 233, 14, 91); 

$text 	= "AAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaargh!!!!";
$text2	= "WTF???";

imagestring ($im, 1, 5, 5,  $text, $text_color );
imagestring($im, 1, 5, 15, $text2, $text_color );
imagestring($im, 1, 5, 25, "WHY DOESN'T THE PNG WORK???", $text_color);
header("Content-type:  image/png");
imagepng ($im);

Code for imagejpeg (same code, different header, different function):

$im = imagecreate ( 250, 100) 
    or die ("Cannot create a new GD image."); 
$background_color = imagecolorallocate ($im, 255, 255, 255); 
$text_color = imagecolorallocate ($im, 233, 14, 91); 

$text 	= "AAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaargh!!!!";
$text2	= "WTF???";

imagestring ($im, 1, 5, 5,  $text, $text_color );
imagestring($im, 1, 5, 15, $text2, $text_color );
imagestring($im, 1, 5, 25, "WHY DOESN'T THE PNG WORK???", $text_color);
header("Content-type:  image/jpeg");
imagejpeg ($im);

Any help with this would be great.

    see if imagepng exists, more specifically, libpng is installed and php is configured --with-png

      libpng is installed /usr/lib/libpng.so.3 and a couple others

        try

        if (function_exists('imagepng')) {
          echo 'imagepng exists.';
        } else {
          echo 'imagepng doesnt exist.';
        }
        

          the code given works fine, make sure you dont have any parse errors. when i look at gdtest.php which is what you are using in your img tag, it shows the content type as text/html and has no output.

            Could it possibly be a folder permissions thing??? Where does GD store tmp images?

              the images are all handled in memory.

                id recommend checkign error logs the try the script from the command line and see if you have any problems. if i try calling the gdtest.php script directly it sends no output.

                  how do you call a script from the command line?? /usr/bin/php /dir/to/my/script.php ?

                    its the way linux tells you a script crashed usually due to problems with pointers. try reinstalling newer versions of the png libraries. thats most likely where the problem is coming from.

                      Write a Reply...