Jump to content

Archived

This topic is now archived and is closed to further replies.

CatDadRick

Help! Division by zero warning

Recommended Posts

I need some help finding the source of this error or warning. I have been getting these messages in my log files for quite some time now. I'm not sure when they started, but I'm getting them constantly. Every 2 -3 minutes...

 

[Wed Nov 26 12:02:34 2008] [error] [client 66.249.73.50] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 183
[Wed Nov 26 12:02:34 2008] [error] [client 66.249.73.50] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 184

 

Here's the function in /catalog/includes/functions/html_output.php...

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)) {
// For testing division by zero error
//	  echo 'height:'.$image_size[1].' width:'.$image_size[0].' for image:'.$src.'<br>'; 

		$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>';
			$rx = $image_size[0] / $width;
			$ry = $image_size[1] / $height;
//			  echo 'ratio:'.$ratio.' for image:'.$src.'<br>';
			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;
}

 

I've added 3 or 4 "echo" statements to see what image has a 0 dimension, but none of them do. What else can be causing this "Division by Zero" Warning?

 

Thanks,

Rick

Share this post


Link to post
Share on other sites

Try changing this line:

 

	if (strstr($width,'%') == false || strstr($height,'%') == false) {

to

 

	if (strstr($width,'%') === false || strstr($height,'%') === false) {

(3 equal signs)


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

=== means: if $a is equal to $b, and they are of the same type.

 

strstr() returns the portion of string, or FALSE if not found.

 

That's why I believe the === operator is required in that situation. Just using == is like comparing to zero.

 

Now I don't know if it will make any difference or not.

:blush:


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

Germ,

 

That didn't seem to make any difference. I've done some more trouble shooting and I think the only time I'm getting this error is when I'm being indexed by googlebot (or another search engine) and also when I open my catalog , click on Catalog and then click on an out of stock item. When I do this I get additional errors that I think are coming from the "'On The Fly' Auto Thumbnailer with GD 2.1" contribution. I've posted to that support thread, but haven't gotten a response.

 

Here are the errors...

[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 185, referer: http://catdads.rlknight.com/products_all.php
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 186, referer: http://catdads.rlknight.com/products_all.php
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 185, referer: http://catdads.rlknight.com/products_all.php
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 186, referer: http://catdads.rlknight.com/products_all.php
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 185, referer: http://catdads.rlknight.com/products_all.php
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 186, referer: http://catdads.rlknight.com/products_all.php
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in /var/www/catalog_live/product_thumb.php on line 310, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecolorallocate(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 313, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagefill(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 315, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecolortransparent(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 316, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 350, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagegif(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 377, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecreate() [<a href='function.imagecreate'>function.imagecreate</a>]: Invalid image dimensions in /var/www/catalog_live/product_thumb.php on line 310, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecolorallocate(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 313, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagefill(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 315, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecolortransparent(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 316, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 350, referer: http://catdads.rlknight.com/product_info.php?products_id=231
[Sat Nov 29 11:02:52 2008] [error] [client 172.16.88.25] PHP Warning:  imagegif(): supplied argument is not a valid Image resource in /var/www/catalog_live/product_thumb.php on line 377, referer: http://catdads.rlknight.com/product_info.php?products_id=231

 

I am unable to reproduce the division be zero error by itself. I think maybe if I could find the error with the Auto Thumbnailer it might solve the division by zero error.

 

Here's the code from catalog/product_thumb.php...

 

// Protect against visitors resizing images at will and eating up your server resources (only allows images up to 4x the original).
if ($_GET['w'] < $image[0] * 4 && $_GET['h'] < $image[1] * 4) {

if (file_exists($filename) && $tn_server_cache && filemtime($filename) > filemtime($_GET['img']))
{
// Output Cache Headers
http_headers($filename);

if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg))
{
	$src = imagecreatefromjpeg($filename);
	imagejpeg($src, '', $jpeg_quality);
}
elseif ($image[2] == 1 && function_exists('imagegif'))
{
	$src = imagecreatefromgif($filename);
	imagegif($src);
}
elseif ($image[2] == 3 || $image[2] == 1)
{
	$src = imagecreatefrompng($filename);
	imagepng($src);
}
else
{
	// Not an image or imagecreatefrom...-function does not exits.
	// Let's output an error
	http_headers();
}
}
else
{
// create thumbnail directory if not exist.
$tmp_path = str_replace(basename($filename), '', $filename);
if (is_dir($tmp_path) == false) mkdir($tmp_path);

// Create a new, empty image based on settings:
if (function_exists('imagecreatetruecolor') && $use_truecolor && ($image[2] == 2 || $image[2] == 3))
{
	$tmp_img = imagecreatetruecolor($_GET['w'],$_GET['h']);
}
else
{
	$tmp_img = imagecreate($_GET['w'],$_GET['h']);
}

$th_bg_color = imagecolorallocate($tmp_img, $r, $g, $b);

imagefill($tmp_img, 0, 0, $th_bg_color);
imagecolortransparent($tmp_img, $th_bg_color);

// Create the image to be scaled:
if ($image[2] == 2 && function_exists('imagecreatefromjpeg'))
{
	$src = imagecreatefromjpeg($_GET['img']);
}
elseif ($image[2] == 1 && function_exists('imagecreatefromgif'))
{
	$src = imagecreatefromgif($_GET['img']);
}
elseif (($image[2] == 3 || $image[2] == 1) && function_exists('imagecreatefrompng'))
{
	$src = imagecreatefrompng($_GET['img']);
}
else
{
	// Not an image or imagecreatefrom...-function does not exits.
	// Let's output an error
	http_headers();
}


// Scale the image based on settings:
if (empty($allow_larger) && ($_GET['w'] > $image[0] || $_GET['h'] > $image[1]))
{
	// existing image is smaller than thumbnail so create the thumbnail
	// with the smaller original image centred on it
	$dx = ($_GET['w'] - $image[0]) / 2;
	$dy = ($_GET['h'] - $image[1]) / 2;
	imagecopy($tmp_img, $src, $dx, $dy, 0, 0, $image[0], $image[1]);
	} else
		if (function_exists('imagecopyresampled') && $use_resampling)
	{
		imagecopyresampled($tmp_img, $src, 0, 0, 0, 0, $_GET['w'], $_GET['h'], $image[0], $image[1]);
	}
	else
	{
		imagecopyresized($tmp_img, $src, 0, 0, 0, 0, $_GET['w'], $_GET['h'], $image[0], $image[1]);
	}

	// Output the image:
	if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg))
	{
		if ($tn_server_cache)
		{
			$thumbnail = modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.jpg');
			imagejpeg($tmp_img,$thumbnail, $jpeg_quality);
			http_headers($thumbnail);
		}
		else
		{
			http_headers($_GET['img']);
		}
		imagejpeg($tmp_img, '', $jpeg_quality);
	}
	elseif ($image[2] == 1 && function_exists('imagegif'))
	{
		if ($tn_server_cache)
		{
			$thumbnail = modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.gif');
			imagegif($tmp_img,$thumbnail);
			http_headers($thumbnail);
		}
		else
		{
			http_headers($_GET['img']);
		}
		imagegif($tmp_img);
	}
	elseif ($image[2] == 3 || $image[2] == 1)
	{
		if ($tn_server_cache)
		{
			$thumbnail = modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.png');
			imagepng($tmp_img,$thumbnail);
			http_headers($thumbnail);
		}
		else
		{
			http_headers($_GET['img']);
		}
		imagepng($tmp_img);
	}
	else
	{
		// Not an image or image...-function not supported
		// Let's output an error:
		http_headers();
	}

	// Clear the image from memory:
	imagedestroy($src);
	imagedestroy($tmp_img);
}
}

 

Any ideas?

 

Thanks,

rick

Share this post


Link to post
Share on other sites

When I go to this page:

 

http://catdads.rlknight.com/product_info.php?products_id=231

Then look in the HTML source:

 

<img src="product_thumb.php?img=images/soldout_product_info.gif&w=0&h=0" border="0" alt="">

That's going to cause a problem (I think).

 

Looks like the width and height parameters are both ZERO.

 

It shows up as a red X on the page.

:o


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

Thanks Germ,

I see what you found. I'm not sure what's causing the h=0 and w=0. The image soldout_product_info.gif is a 75x75 px image. I have contribution, Shoppe_enhancements_controller, that allows me to use text for sold out product rather than the image. I didn't like the image, so I'm using text. I can change back to the image and see if the problem persists. I'll post back here.

 

Thanks,

Rick

Share this post


Link to post
Share on other sites

Same problem here:

 

http://catdads.rlknight.com/products_all.php?sort=3a&page=2


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

×