Current location: Hot Scripts Forums » Programming Languages » PHP » help with error messages.. please


help with error messages.. please

Reply
  #1 (permalink)  
Old 10-03-06, 04:08 PM
APuppyDog APuppyDog is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
help with error messages.. please

Hello, In my cPanel error logs, i see a lt of repeated errors like the one below. I have pasted the makethumb1.php code as well.. can anyone figure out why i'm getting this error message?

error:
Quote:
[Tue Oct 3 20:45:41 2006] [error] PHP Warning: Division by zero in /home/bad/public_html/car/makethumb1.php on line 315
[Tue Oct 3 20:45:41 2006] [error] PHP Warning: Division by zero in /home/bad/public_html/car/makethumb1.php on line 311
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 347
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 345
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagestring(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 343
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagefilledrectangle(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 339
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 337
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 335
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in /home/bad/public_html/car/makethumb1.php on line 333
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: Division by zero in /home/bad/public_html/car/makethumb1.php on line 315
[Tue Oct 3 20:45:35 2006] [error] PHP Warning: Division by zero in /home/bad/public_html/car/makethumb1.php on line 311
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 347
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 345
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagestring(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 343
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagefilledrectangle(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 339
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 337
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/bad/public_html/car/makethumb1.php on line 335
[Tue Oct 3 20:45:29 2006] [error] PHP Warning: imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in /home/bad/public_html/car/makethumb1.php on line 333
makethumb1.php:
PHP Code:

<?


## 

$code 'function gd_info() {

       $array = Array(

                       "GD Version" => "",

                       "FreeType Support" => 0,

                       "FreeType Support" => 0,

                       "FreeType Linkage" => "",

                       "T1Lib Support" => 0,

                       "GIF Read Support" => 0,

                       "GIF Create Support" => 0,

                       "JPG Support" => 0,

                       "PNG Support" => 0,

                       "WBMP Support" => 0,

                       "XBM Support" => 0

                     );

       $gif_support = 0;



       ob_start();

       eval("phpinfo();");

       $info = ob_get_contents();

       ob_end_clean();

     

       foreach(explode("\n", $info) as $line) {

           if(strpos($line, "GD Version")!==false)

               $array["GD Version"] = trim(str_replace("GD Version", "", strip_tags($line)));

           if(strpos($line, "FreeType Support")!==false)

               $array["FreeType Support"] = trim(str_replace("FreeType Support", "", strip_tags($line)));

           if(strpos($line, "FreeType Linkage")!==false)

               $array["FreeType Linkage"] = trim(str_replace("FreeType Linkage", "", strip_tags($line)));

           if(strpos($line, "T1Lib Support")!==false)

               $array["T1Lib Support"] = trim(str_replace("T1Lib Support", "", strip_tags($line)));

           if(strpos($line, "GIF Read Support")!==false)

               $array["GIF Read Support"] = trim(str_replace("GIF Read Support", "", strip_tags($line)));

           if(strpos($line, "GIF Create Support")!==false)

               $array["GIF Create Support"] = trim(str_replace("GIF Create Support", "", strip_tags($line)));

           if(strpos($line, "GIF Support")!==false)

               $gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));

           if(strpos($line, "JPG Support")!==false)

               $array["JPG Support"] = trim(str_replace("JPG Support", "", strip_tags($line)));

           if(strpos($line, "PNG Support")!==false)

               $array["PNG Support"] = trim(str_replace("PNG Support", "", strip_tags($line)));

           if(strpos($line, "WBMP Support")!==false)

               $array["WBMP Support"] = trim(str_replace("WBMP Support", "", strip_tags($line)));

           if(strpos($line, "XBM Support")!==false)

               $array["XBM Support"] = trim(str_replace("XBM Support", "", strip_tags($line)));

       }

       

       if($gif_support==="enabled") {

           $array["GIF Read Support"]  = 1;

           $array["GIF Create Support"] = 1;

       }



       if($array["FreeType Support"]==="enabled"){

           $array["FreeType Support"] = 1;    }

 

       if($array["T1Lib Support"]==="enabled")

           $array["T1Lib Support"] = 1;    

       

       if($array["GIF Read Support"]==="enabled"){

           $array["GIF Read Support"] = 1;    }

 

       if($array["GIF Create Support"]==="enabled")

           $array["GIF Create Support"] = 1;    



       if($array["JPG Support"]==="enabled")

           $array["JPG Support"] = 1;

           

       if($array["PNG Support"]==="enabled")

           $array["PNG Support"] = 1;

           

       if($array["WBMP Support"]==="enabled")

           $array["WBMP Support"] = 1;

           

       if($array["XBM Support"]==="enabled")

           $array["XBM Support"] = 1;

       

       return $array;

   }'
;



function 
gd_version() {

    global 
$code;

    if (empty(
$result)) {

        if (!
function_exists('gd_info')) $gd_info = eval($code);

        else 
$gd_info gd_info();

        

        if (
substr($gd_info['GD Version'], 0strlen('bundled (')) == 'bundled (') {

            
$result = (float) substr($gd_info['GD Version'], strlen('bundled ('), 3); 

        } else {

            
$result = (float) substr($gd_info['GD Version'], 03); 

        }

    }

    return 
$result;

}



function 
ImageCreateFunction($x_size$y_size) {

    
$ImageCreateFunction 'ImageCreate';

    if (
gd_version() >= 2.0) {

        
$ImageCreateFunction 'ImageCreateTrueColor';

    }

    if (!
function_exists($ImageCreateFunction)) {

        return 
FALSE;

    }

    return 
$ImageCreateFunction($x_size$y_size);

}



function 
ImageCopyFunction($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH) {

    
$ImageCopyFunction 'ImageCopyResized';

    if (
gd_version() >= 2.0) {

        
$ImageCopyFunction 'ImageCopyResampled';

    }

    if (!
function_exists($ImageCopyFunction)) {

        return 
FALSE;

    }

    return 
$ImageCopyFunction($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);

}



function 
generateThumb($sourceFilename$thumb_x$square=FALSE$border=FALSE) {

    
$image_info getimagesize($sourceFilename);

    
$image_width $image_info[0];

    
$image_height $image_info[1];

    

    if (
$image_width<$thumb_x$thumb_x $image_width;

    

    if (
$square) { 

        
$thumb_image_x 468;

        
$thumb_image_y 60;

    }



    
// workaround for v1.6.2 where the GIF images arent recognized.

    
$ImgCreate 'ImageCreateFromJPEG';

    switch (
$image_info['mime']) {

        case 
'image/gif':

            
$ImgCreate 'ImageCreateFromGIF';

            break;

        case 
'image/jpeg':

            
$ImgCreate 'ImageCreateFromJPEG';

            break;

        case 
'image/png':

            
$ImgCreate 'ImageCreateFromPNG';

            break;

    }



    if (!
$square) {

        
$shrinkratio $image_width/$thumb_x;

        
$thumb_y $image_height/$shrinkratio;

        
$start_x 0;

        
$start_y 0;

    } else if (
$square) {

        if (
$image_width>$image_height) {

            
$shrinkratio $image_width/$thumb_x;

            
$thumb_y $image_height/$shrinkratio;

            
$start_x 0;

            
$start_y = (abs($thumb_image_y $thumb_y)) / 2;

        } else if (
$image_width<=$image_height) {

            
$shrinkratio $image_height/$thumb_x;

            
$thumb_y =$thumb_x;

            
$thumb_x $image_width/$shrinkratio;

            
$start_y 0;

            
$start_x = (abs($thumb_image_x $thumb_x)) / 2;

        }

    }

    

    
$thumbInput = @$ImgCreate($sourceFilename); 



       if (!
$thumbInput) { /* See if it failed */

        
$thumbInput  imagecreate($thumb_x$thumb_y); /* Create a blank image */

           
$bgc imagecolorallocate($thumbInput255255255);

           
$tc  imagecolorallocate($thumbInput000);

           
imagefilledrectangle($thumbInput0015030$bgc);

           
/* Output an errmsg */

           
imagestring($thumbInput155"Error loading $sourceFilename"$tc);

        
imagejpeg($thumbInput,'',90);

        
imagedestroy($thumbInput);

       } else {

        if (
$square) {

            
$thumbOutput ImageCreateFunction($thumb_image_x,$thumb_image_y) or die("couldn't create image"); 

            
$border_x $thumb_image_x 1;

            
$border_y $thumb_image_y 1;

        } else {

            
$thumbOutput ImageCreateFunction($thumb_x,$thumb_y) or die("couldn't create image"); 

            
$border_x $thumb_x 1;

            
$border_y $thumb_y 1;

        }

    

        
$background_color imagecolorallocate($thumbOutput255255255);

        
imagefill($thumbOutput,0,0,$background_color);

        
ImageCopyFunction($thumbOutput,$thumbInput,$start_x,$start_y,0,0,$thumb_x,$thumb_y,$image_width,$image_height) or die("coudln't resize image"); 

        if (
$border) {

            
$border_color imagecolorallocate($thumbOutput000);

            
imagerectangle($thumbOutput,0,0,$border_x,$border_y,$border_color) or die("couldn't create image"); 

        }

    

        
imagejpeg($thumbOutput,'',90);

        
imagedestroy($thumbOutput);

    }

}



### here we call the function, and we get the GET parameters;

$pic $_GET['pic'];

$thumbWidth $_GET['w'];

$isSquare = ($_GET['sq']=='Y')? TRUE FALSE;

$isBorder = ($_GET['b']=='Y') ? TRUE FALSE;



## if check is submitted then do the queries needed, otherwise create the pics

if ($_GET['check']=="phpinfo") {

    
phpinfo();

} else if (
$_GET['check']=="gdinfo") {

    
gd_info();

} if (
$_GET['check']=="") {

    if (isset(
$pic)&&$thumbWidth>0) {

        
header("Content-type: image/jpeg");

        
generateThumb($pic$thumbWidth$isSquare$isBorder);

    } else if (!isset(
$pic)) {

        echo 
"<strong>ERROR:</strong> No image submitted";

    } else if (
$thumbWidth<=0) {

        echo 
"<strong>ERROR:</strong> Invalid resizing option";

    }

}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-04-06, 01:49 AM
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
Most likely all the errors are being caused by one initial problem.

Examining lines 311 and 315, looking for what would cause the error message given for those lines (Division by zero), we can see that $thumb_x has a zero value.

This is the second parameter in the function -
PHP Code:

function generateThumb($sourceFilename$thumb_x$square=FALSE$border=FALSE) { 

There is a call to this function at line #425 -
PHP Code:

generateThumb($pic$thumbWidth$isSquare$isBorder); 

This function is only called if the $thumbWidth is greater than zero, so it leaves the lines in the function that modify $thumb_x. The following lines can set $thumb_x to zero, if $image_width is zero -
Code:
237:     $image_info = getimagesize($sourceFilename);    
238:   
239:     $image_width = $image_info[0];    
240:   
241:     $image_height = $image_info[1];    
242:   
243:         
244:   
245:     if ($image_width<$thumb_x) $thumb_x = $image_width;
The function getimagesize(...) can return a FALSE value if the file it is testing is not an image. In this case, $image_width would be null/zero, which is causing the first two error messages. The other error messages are probably (I only traced through the errors to the point of determining the above information) because the file name in $sourceFilename is not an image. The code should test for a FALSE value returned by getimagesize(...) and take appropriate action.
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 10-06-06, 12:09 AM
APuppyDog APuppyDog is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
thank you, it was stray code left from a javascript my programmer was using.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
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


All times are GMT -5. The time now is 07:09 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.