Jump to content
Sign in to follow this  
CatDadRick

Division by zero

Recommended Posts

I am getting a "division by zero" PHP Warning in my log files along with another PHP Warning. The Divide by zero warning seems to happen in pairs as below...

 

[Thu Nov 13 18:47:24 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in catalog/includes/functions/html_output.php on line 180, referer: [url="http://catdads.rlknight.com/index.php?cPath=3_85"]http://catdads.rlknight.com/index.php?cPath=3_85[/url]
[Thu Nov 13 18:47:24 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in catalog/includes/functions/html_output.php on line 181, referer: [url="http://catdads.rlknight.com/index.php?cPath=3_85"]http://catdads.rlknight.com/index.php?cPath=3_85[/url]
[Thu Nov 13 18:47:24 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in catalog/includes/functions/html_output.php on line 180, referer: [url="http://catdads.rlknight.com/index.php?cPath=3_85"]http://catdads.rlknight.com/index.php?cPath=3_85[/url]
[Thu Nov 13 18:47:24 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in catalog/includes/functions/html_output.php on line 181, referer: [url="http://catdads.rlknight.com/index.php?cPath=3_85"]http://catdads.rlknight.com/index.php?cPath=3_85[/url]

 

The other PHP Warning is this...

 

[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning:  imagecreate() [<a href='function.im

agecreate'>function.imagecreate</a>]: Invalid image dimensions in catalog/product_thumb.php on line 310
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning:  imagecolorallocate(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 313
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning:  imagefill(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 315
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning:  imagecolortransparent(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 316
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning:  imagecopyresampled(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 350
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning:  imagegif(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 377

 

Here's the code in catalog/includes/functions/html_output.php that seems to be causing the first warning...

 

           // Scale the image if not the original size
           if ($image_size[0] != $width || $image_size[1] != $height) {
//            echo 'variable1:'.$width;
//            echo 'variable1:'.$height;
               $rx = $image_size[1] / $width;
               $ry = $image_size[1] / $height;

               if ($rx < $ry) {
                   $width = intval($height / $ratio);
               } else {
                   $height = intval($width * $ratio);
               }

               $image = '<img src="product_thumb.php?img=' . $src . '&w=' .
               tep_output_string($width) . '&h=' . tep_output_string($height) . '"';
           }

 

Can someone tell me how to get rid of these warnings? I have error_reporting turned off in php.ini so the warnings don't show up on my pages, but my log files are getting pretty full.

 

Thanks,

Rick Knight

Share this post


Link to post
Share on other sites

Looks like a code snippet from function tep_image

 

Please post all of the code for that one function only, please.


If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Share this post


Link to post
Share on other sites
Looks like a code snippet from function tep_image

 

Please post all of the code for that one function only, please.

 

Germ, thanks for the reply. Yes, that was a snippet from function tep_image. Full function below. I was able to fix the "division by zero" warning. I had replaced the Out of Stock image with an out of stock message but didn't change my shoppe_enhancements_controller.php to reflect the change. I am still seeing the other warnings in my log files though.

 

Here are the PHP Warnings again,

[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning: imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in catalog/product_thumb.php on line 310
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning: imagecolorallocate(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 313
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning: imagefill(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 315
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning: imagecolortransparent(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 316
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning: imagecopyresampled(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 350
[Fri Nov 14 16:16:11 2008] [error] [client 65.55.108.172] PHP Warning: imagegif(): supplied argument is not a valid Image resource in catalog/product_thumb.php on line 377

 

Here's function tep_image in full,

function tep_image($src, $alt = '', $width = '', $height = '', $params = '') {

 // if no file exists display the 'no image' file
 if (!is_file($src)) {
 $src = "images/no_image.jpg";
 }
   // Set default image variable and code
   $image = '<img src="' . $src . '"';

   // Don't calculate if the image is set to a "%" width
   if (strstr($width,'%') == false || strstr($height,'%') == false) {
       $dont_calculate = 0;
   } else {
       $dont_calculate = 1;
   }

   // Dont calculate if a pixel image is being passed (hope you dont have pixels for sale)
   if (!strstr($image, 'pixel')) {
       $dont_calculate = 0;
   } else {
       $dont_calculate = 1;
   }

   // Do we calculate the image size?
   if (CONFIG_CALCULATE_IMAGE_SIZE && !$dont_calculate) {

       // Get the image's information
       if ($image_size = @getimagesize($src)) {

           $ratio = $image_size[1] / $image_size[0];

           // Set the width and height to the proper ratio
           if (!$width && $height) {
               $ratio = $height / $image_size[1];
               $width = intval($image_size[0] * $ratio);
           } elseif ($width && !$height) {
               $ratio = $width / $image_size[0];
               $height = intval($image_size[1] * $ratio);
           } elseif (!$width && !$height) {
               $width = $image_size[0];
               $height = $image_size[1];
           }

           // Scale the image if not the original size
           if ($image_size[0] != $width || $image_size[1] != $height) {
//            echo 'variable1:'.$width;
//            echo 'variable1:'.$height;
//echo 'height:'.$height.' width:'.$width.' for image:'.$src.'<br>'; /* Added to troubleshoot "Division by zero" */
               $rx = $image_size[1] / $width;
               $ry = $image_size[1] / $height;

               if ($rx < $ry) {
                   $width = intval($height / $ratio);
               } else {
                   $height = intval($width * $ratio);
               }

               $image = '<img src="product_thumb.php?img=' . $src . '&w=' .
               tep_output_string($width) . '&h=' . tep_output_string($height) . '"';
           }

       } elseif (IMAGE_REQUIRED == 'false') {
           return '';
       }
   }

   // Add remaining image parameters if they exist
   if ($width) {
       $image .= ' width="' . tep_output_string($width) . '"';
   }

   if ($height) {
       $image .= ' height="' . tep_output_string($height) . '"';
   }

   if (tep_not_null($params)) $image .= ' ' . $params;

   $image .= ' border="0" alt="' . tep_output_string($alt) . '"';

   if (tep_not_null($alt)) {
       $image .= ' title="' . tep_output_string($alt) . '"';
   }

   $image .= '>';

   return $image;
}

 

Any idea where these warnings are coming from and how to fix them?

 

Thanks Rick

Share this post


Link to post
Share on other sites

I thought I had solved the division by zero warnings, but I was wrong. I am still getting the warning in my logs. I've enabled this bit of added code to spot the zero size variable, but it does not show any height or width of zero. Everything looks OK, but I still get the warning.

 

echo 'height:'.$height.' width:'.$width.' for image:'.$src.'<br>';

 

Any ideas, anyone?

 

Thanks,

Rick

Share this post


Link to post
Share on other sites

This code:

 

				$rx = $image_size[1] / $width;
			$ry = $image_size[1] / $height;

Should be:

 

				$rx = $image_size[0] / $width;
			$ry = $image_size[1] / $height;

Can't say for sure if that will help at all.


If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Share this post


Link to post
Share on other sites
This code:

 

				$rx = $image_size[1] / $width;
			$ry = $image_size[1] / $height;

Should be:

 

				$rx = $image_size[0] / $width;
			$ry = $image_size[1] / $height;

Can't say for sure if that will help at all.

 

Thanks Germ,

 

I've made this change. I'll see if it works.

 

Rick Knight

Share this post


Link to post
Share on other sites
This code:

 

				$rx = $image_size[1] / $width;
			$ry = $image_size[1] / $height;

Should be:

 

				$rx = $image_size[0] / $width;
			$ry = $image_size[1] / $height;

Can't say for sure if that will help at all.

 

Graham,

 

I tried the above change. Didn't make any difference. Any other idesa? Anyone?

 

Thanks,

Rick

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×