Hello,
I am attempting to utilize PHP GD programming for the first time and am having some issues. My server supports GD. Everything has already been verified to be working correctly. I just cannot understand why the picture won't output. I have gotten an image to output with extremely very simple code but not with the code below.

Current Issue
I have tried some very simple code to attempt to get 1 picture to show up. I am not sure what is happening. I still cannot get a picture to show up. I have the correct header information. I have the correct pathway.

URL: http://67.199.62.141/test3.php
1. Does not output an image. I believe something is getting lost within the switch case statement but I don't know what.

Note:
Below is an image that is located in our root directory. http://67.199.62.141/scrfix-logo.png if you want to test this on your own server.

<?php

header ('Content-Type: image/png'); // What type of image are we working with?
$image = open_image('SCRFix-logo.png'); // Where is the image located?

//Check to see if we can find the image
if ($image === false) {
        die ('Unable to find image');
}

echo 'Found and Opened image';  //Did we successfully find this image?  Please note that for some reason when we do find the image.  This disappears.  If I comment out everything below.  This shows up and says open image.  When I attempt to display the image, this no longer outputs to the browser.

function open_image($file) {
        // What extension are we working with?
        $extension = strrchr($file, '.');
        $extension = strtolower($extension);

    switch($extension) {
            case '.jpg':
            case '.jpeg':
                    $im = @imagecreatefromjpeg($file);
                    break;
            case '.gif':
                    $im = @imagecreatefromgif($file);
                    break;
            case '.png':
                    $im = @imagecreatefrompng($file);
                    break;

            // ... etc ... etc ...etc (I did not include the rest here to keep this short)

            default:
                    $im = false;
                    break;
    }

    return $im;
}


imagepng($image); // Output to browser directly through GD Code however this doesn't return an image.

?>

Please help...

Thanks,

Wayne

    This issue has been resolved.

    The echo statement that I included within the above was messing it up. It outputs with no problems otherwise. As soon as I commented that out, the image showed up immediately. Now just to get an array of images to appear and I will be well on my way to having what appears to be one of the first PHP/JavaScript Resolution detection and resize your images and fonts accordingly scripts. 😃

    Wayne

      Write a Reply...