Current location: Hot Scripts Forums » Programming Languages » PHP » GD 2+ Generates Black Thumbnail!


GD 2+ Generates Black Thumbnail!

Reply
  #1 (permalink)  
Old 01-18-06, 05:40 AM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Question GD 2+ Generates Black Thumbnail!

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.
__________________
Reply With Quote
  #2 (permalink)  
Old 01-18-06, 03:36 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Is this line just due to posting here or is the source like that (white space between $thum and b_w) -
PHP Code:

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thum  b_w,$thumb_h,$old_x,$old_y); 

The $thum b_w might be causing a zero width result.
Reply With Quote
  #3 (permalink)  
Old 01-18-06, 06:51 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Reply With Quote
  #4 (permalink)  
Old 01-18-06, 11:46 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
Yeah, that white space is because of the forum software. It doesn't exist in my function.



Quote:
Originally Posted by mab
Is this line just due to posting here or is the source like that (white space between $thum and b_w) -
PHP Code:

imagecopyresampled($dst_img,$src_img,0,0,0,0,$thum b_w,$thumb_h,$old_x,$old_y); 

The $thum b_w might be causing a zero width result.
__________________
Reply With Quote
  #5 (permalink)  
Old 01-18-06, 11:48 PM
digioz's Avatar
digioz digioz is offline
Community VIP
 
Join Date: Oct 2003
Location: Chicago, IL
Posts: 2,171
Thanks: 3
Thanked 9 Times in 9 Posts
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.
__________________
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect After PHP GD Script dodotopia PHP 1 08-15-05 09:19 AM
What is GD Library matej The Lounge 2 12-26-04 05:35 PM
Php Gd proteome PHP 3 08-20-04 05:13 PM
photo gallery w/formfields for each thumbnail mikeyzc PHP 2 05-28-04 01:16 PM
photo gallery w/form fields for each thumbnail mikeyzc Script Requests 0 05-28-04 06:48 AM


All times are GMT -5. The time now is 06:28 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.