Jump to content

Error-images not showing from thumbnail script


ryanb

Recommended Posts

Hello,

I have a PHP script that cuts-out a portion of a full-sized image and uses it for a thumbnail image on a page.  If the full-sized image doesn't exists, then a generic image is created to take its place.  My problem is that these error images work/show-up on my own machine, but not on my host.  From a phpinfo(), we both have GD 2.0.28 compatiable under PHP 5.1.2 for me and PHP 4.4.2 for them.  I checked and all of the functions used should be supported by the older PHP 4.  The creation of thumbnails when the image can be found works fine on the host, just not the error image.  This is the error image generation part:

[code]// Size of full-size image
$full = $root . $full . '.png';                                        // The full path of the file (assumes it is PNG)
$full = str_replace(' ', '%20', $full);                                // Encode any spaces in the filename correctly
$full_dim = getimagesize($full);

if ($full_dim == FALSE) {                                              // Check to see if the file exists

    $error_img = imagecreatetruecolor($thumb_width, $thumb_height) OR exit('New GD stream failed.');
    $background = imagecolorallocate($error_img, 0xbc, 0xd5, 0xe7);    // The full color is #bcd5e7 (a blue), the same as the background of <body>
    $text = imagecolorallocate($error_img, 0, 0, 0);
    imagefilledrectangle($error_img, 0, 0, $thumb_width, $thumb_height, $background);
    imagestring($error_img, 1, 10, 9, 'File not found.', $text);      // Draw error message in image

    header('Content-type: image/png');
    imagepng($error_img);
    imagedestroy($error_img);
    exit(0);

} else {

    //  Stuff for when the file is found
[/code]

Thank you for your help!
Link to comment
Share on other sites

Image not showing is rather vague. Sometimes when I get a bad image script, it will just make a the whole image black. If the webpage is also black ... you get the idea.

Try making a separate script with just the error image code. Run it directly from your browser and see what it does. If there's a problem you should be getting an error (you will have to comment the header to see late errors -- that or use CURL).
Link to comment
Share on other sites

  • 3 weeks later...
I figured out the problem; it was this bit:

[code]$full_dim = getimagesize($full);

if ($full_dim == FALSE) {[/code]

because I was running the script using dreamhost.com, and a getimagesize() returning FALSE causes the script to stop or something (for security reasons maybe?)  So to fix it, I changed only a couple of lines and worked things around the file_exists() function so that the error-image is created on the basis of file_exists() returning FALSE rather than getimagesize().

Thanks for your help!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.