Jump to content


This topic is now archived and is closed to further replies.


Error-images not showing from thumbnail script

Recommended Posts


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');

} else {

    //  Stuff for when the file is found

Thank you for your help!

Share this post

Link to post
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).

Share this post

Link to post
Share on other sites
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!

Share this post

Link to post
Share on other sites


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.