Jump to content


Error-images not showing from thumbnail script

  • Please log in to reply
2 replies to this topic

#1 ryanb

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 02 October 2006 - 03:55 AM


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:

// 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!

#2 michaellunsford

  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 02 October 2006 - 07:00 PM

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).

#3 ryanb

  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 18 October 2006 - 04:46 AM

I figured out the problem; it was this bit:

$full_dim = getimagesize($full);

if ($full_dim == FALSE) {

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!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users