I have a PHP code that generates thumbnails on the fly. I have been using it without a problem on both Windows and Linux Servers for a while now. However on a new server we recently aquired, the resulting thumbnails are a black rectangular box (dimesion 100x100).
Anyone know anything about this issue? I am posting the code I use to generate the thumbnail FYI:
PHP Code:
function createthumb($name,$filename,$new_w,$new_h) { $system=explode(".",$name); if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); }
The Server has the following GD Information:
Code:
GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
I would appreciate any info on this issue. Thanks.
I tried this on a PHP4 windows shared hosting system and a local PHP5 windows development system and it works OK. About the only problem I had that duplicates what you are seeing is when the source $name file does not exist or is not at the path used in the call to the function. The imagecreatefrom... function returns a false.
I am 100% sure that both the path is correct and the image file exists in the path specified. So I am sure that's not it, although either of those two mistakes would generate a similar black thumbnail.
Quote:
Originally Posted by mab
I tried this on a PHP4 windows shared hosting system and a local PHP5 windows development system and it works OK. About the only problem I had that duplicates what you are seeing is when the source $name file does not exist or is not at the path used in the call to the function. The imagecreatefrom... function returns a false.