Latest News: (loading..)
mloeffen

'On The Fly' Auto Thumbnailer using GD Library 2.1

555 posts in this topic

I installed this contribution several months ago and all seemed OK, but yesterday while trying to debug a "division by zero" warning,

 

I thought I had solved the "division by zero" warnings but I was wrong, I'm still getting them...

[Tue Nov 18 15:56:24 2008] [error] [client 172.16.88.5] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 181, referer: http://catdads.rlknight.com/index.php?cPath=12_34
[Tue Nov 18 15:56:24 2008] [error] [client 172.16.88.5] PHP Warning:  Division by zero in /var/www/catalog_live/includes/functions/html_output.php on line 182, referer: http://catdads.rlknight.com/index.php?cPath=12_34

 

Here's the tep_image function from my html_output.php...

// Scales product images dynamically, resulting in smaller file sizes, and keeps
// proper image ratio. Used in conjunction with product_thumb.php t/n generator.
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>';
			$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;
}
// End Replace

 

I was getting the warning on the page every time I loaded the CATALOG page, but I had modified my shop to show a text message for out of stock items hadn't changed my "shoppe_enhancements_controller.php" file to reflect the modification. I corrected that and got rid of the on page warning message but I'm still getting the warning in my log file and I can't tell where it's coming from. I added code to show the $height and $width variables and the image name, but that didn't show any zero size images.

 

Any idea what's causing this?

 

Thanks,

Rick

Share this post


Link to post
Share on other sites
Hello to everybody!

I am trying to make run a "on the fly" im my osc commerce, but its quite imposible for me right now, i try to install the "otf autothumb v2.4fix3" i replace the files, and upload de mysql file, but when i am trying to enter to the admin./.catalog in this file

 

http://www.soloazar.com.ar/catalog/admin/categories.php?selected_box=catalog

 

apears this error

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/soloazar.com.ar/htdocs/catalog/admin/includes/functions/database.php on line 99

 

in the line 99 i have this

 

function tep_db_fetch_array($db_query) {

return mysql_fetch_array($db_query, MYSQL_ASSOC);

}

 

And im really confused, because i dont know how to solve it.

 

The only contribution instaled in the osc, before thisone is the sts template system.

 

Any Help will be eternaly regarded.

 

 

I am getting the same error. Anyone know of a fix?

Share this post


Link to post
Share on other sites
I am getting the same error. Anyone know of a fix?

 

I figured it out. I manually added the changes to admin/categories.php and the error went away. I believe that the file provided has some additional addon that was included in that file causing the error. Make the changes by comparing the files and only adding what you see inside the comments and you will get it to work.

Share this post


Link to post
Share on other sites

I have a problem. All my thumbs directories with images are permission denided for me. So, I can't delete them or files in it via ftp. No changes for mkdir were in product_thumbs.php. Thumbs directories created should be 777, but they are 755.

Does any body have this problem? ((

Share this post


Link to post
Share on other sites

Another great contribution! Thanks :).

Everything is working perfectly, allthough i would love to have one thing rescripted.

At this point, when entering a new product or changing an existing products details, there are 2 fields for uploading pictures ( i dont really understand why there are 2?) I want to rescript the auto thumbnailing (which uses the same picture as in enlarge popup), and use the 2 fields in the new product details screen (admin) for:

Field 1: To upload a picture that will be used in the enlargened popup.

Field 2: To upload a picture that will be used in the thumbnail box.

The reason i want to do this is to use watermarks in my enlargened pictures. I dont want these to show in the thumbnails. Does anyone know how i can fix this?

 

Help would be more than appreciated

Share this post


Link to post
Share on other sites

Thanks for a great contribution! We're trying to install it now and have a quick question about a potentially missing file:

 

The readme file says, "Make a backup of the files that are going to be changed:

<snip>

* catalog/admin/includes/categories.php

<snip>"

 

But we do not have an admin/includes/categories.php file.

Should we?

 

We do have Categories in the store.

We do have an admin/categories.php file.

Share this post


Link to post
Share on other sites

Hi,

This is a wonderful contribution but after installing it I am having a tiny problem with our current design. For some reason, a small spacer image is not showing up after the installation. If you go to gsmfanatics.com, you will see it in the header, along the tabs, on each corner the spacer image is missing.. If someone could help me out I would sincerely appreciate that.

 

Thank you!!

Share this post


Link to post
Share on other sites

This mod is great except it uploads pictures with a permission of 777. Is there any way to make it upload them already at 644?

 

Tim

Share this post


Link to post
Share on other sites

Sweet contrib!

Basic install works like a charm.

Way less image loading time!

 

I'll definetly install the extras ;>

 

:thumbsup:

Share this post


Link to post
Share on other sites

Hi All,

 

Would like to know that, how do i prevent Auto Thumbnailer from resizing the spacer.gif at the size of 1px x 1px ... because it messy the theme design that used spacer image.

 

i have tried following,

 

// Don't calculate if the image is set to a "%" width

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

$dont_calculate = 0;

} else {

$dont_calculate = 1;

}

 

and even

 

// Dont calculate if a pixel image is being passed (hope you dont have pixels for sale)

if (!strstr($image, 'pixel') || (!strstr($image, 'spacer')) {

$dont_calculate = 0;

} else {

$dont_calculate = 1;

}

 

Hi, anyone know how to solve this ?

 

Thanks

 

 

 

Hi,

 

Anyone figured this out yet ? When I load the new html_outpout.php file my spacer.gif go 1px x 1px and also my backrgound gif is affected and my layout is completely messed ..

 

Hope to solve this asap :)

 

Thanks !

Share this post


Link to post
Share on other sites

Is there a way to just turn off gif support maybe ? This would also solve problem probably ...

Edited by suhy

Share this post


Link to post
Share on other sites
Hi All,

 

Would like to know that, how do i prevent Auto Thumbnailer from resizing the spacer.gif at the size of 1px x 1px ... because it messy the theme design that used spacer image.

 

i have tried following,

 

// Don't calculate if the image is set to a "%" width

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

$dont_calculate = 0;

} else {

$dont_calculate = 1;

}

 

and even

 

// Dont calculate if a pixel image is being passed (hope you dont have pixels for sale)

if (!strstr($image, 'pixel') || (!strstr($image, 'spacer')) {

$dont_calculate = 0;

} else {

$dont_calculate = 1;

}

 

 

 

 

 

Hi,

 

Anyone figured this out yet ? When I load the new html_outpout.php file my spacer.gif go 1px x 1px and also my backrgound gif is affected and my layout is completely messed ..

 

Hope to solve this asap :)

 

Thanks !

 

 

Hi again :))

 

It seems I have found a solution to this ..... The following autothumbnailer doesnt have these issues with spacer.gif ....

 

http://www.oscommerce.com/community/contributions,2872/

 

It works for me :))

 

Try it !

Share this post


Link to post
Share on other sites

Hello Amigos,

Everything with this contribution was working fine, but something must have changed.. When I click the image, nothing pops up. My server is not logging any errors. I've tried it on two computers so far.

 

The site is http://www.rootworkherbs.com

 

I'd really appreciate it if anyone could point me in the right direction to get this fixed.

 

Thanks!

 

Scott

Share this post


Link to post
Share on other sites

Hi. I got a problem with image resizing. Installation was without any problem. Contribution works fine. But when i upload an image with smaller size (than height and width in admin panel), i got original image with thick black borders. Hot to fix this? Maybe white borders? Is this bug of gd library?

Share this post


Link to post
Share on other sites

Hi!

 

Great contribution! :) I just installed it and it seems to be working very well.

 

One problem: because I replaced the tep_image function, I lost some previous modifications I made in that function that allowed swf to be handled as an embedded image. Some of my products are small flash movies/games, and it was nice having them display on product info pages and in the specials, etc. (even though they were downsized in the stock OsCommerce method of "squish it down").

 

Is there a way to add back in some kind of code that says "if a file is swf, bypass thumbnail function and pass it through as an embed"?

 

I really hope someone can help me with this. I've been fooling around with it, but each time I think i have it, I am rudely awakened!

 

Thanks so much!

Share this post


Link to post
Share on other sites

what have u tried.

 

I'd have thought a simple test such as

 

if (strstr($src, '.swf')) return tep_image_original ($src, $alt, $width, $height, $params);

 

would do. ;)

Share this post


Link to post
Share on other sites
what have u tried.

 

I'd have thought a simple test such as

 

////
// The HTML image wrapper function

function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '', $swf = 'no') {
  if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
    return false;
  }
$extension = substr($src, -4);
if ($extension == '.swf') $swf = 'yes';

// alt is added to the img tag even if it is null to prevent browsers from outputting
// the image filename as default
if ($swf == 'no') {
   $image = '<img src="' . tep_output_string($src) . '" border="0" alt="' . tep_output_string($alt) . '"';
} else {
   $image = '<embed src="' . tep_output_string($src) . '"';
}

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

  if (((CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height))) && ($swf=='no')) {
    if ($image_size = @getimagesize($src)) {
      if (empty($width) && tep_not_null($height)) {
        $ratio = $height / $image_size[1];
        $width = $image_size[0] * $ratio;
      } elseif (tep_not_null($width) && empty($height)) {
        $ratio = $width / $image_size[0];
        $height = $image_size[1] * $ratio;
      } elseif (empty($width) && empty($height)) {
        $width = $image_size[0];
        $height = $image_size[1];
      }
    } elseif (IMAGE_REQUIRED == 'false') {
      return false;
    }
  }

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

  if ((tep_not_null($parameters)) && ($swf =='no')) $image .= ' ' . $parameters;

  $image .= '>';

  return $image;
}

////

 

The OTF contribution replaced all that - and there is no reference at all to swf - although I thought I saw it mentioned in some of the earlier versions.

 

Basically, I've been trying to integrate the bits of the old code that referenced swf into the new OTF code. I've also tried a few of the contributions that activate flash, but they are mainly for hard-coded embeds of swf on pages. They haven't had any effect on the product images.

 

BTW, the flash files ARE being thumbed - i can see the "thumb" string in the URL - but they just aren't rendering - all I get is an empty box. :(

 

Thanks for any ideas...

Share this post


Link to post
Share on other sites

sorry, I though u knew what u were doing!!

 

put back your original function, renaming it to tep_image_original

 

then put

 

if (substr($src, -4) == '.swf') return tep_image_original ($src, $alt, $width, $height, $params);

 

at the start of the new function

Share this post


Link to post
Share on other sites
put back your original function, renaming it to tep_image_original

 

then put

 

if (substr($src, -4) == '.swf') return tep_image_original ($src, $alt, $width, $height, $params);

 

at the start of the new function

 

Oh got it!! That works a treat!! :)

 

It never even occurred to me to use the whole original function in it's entirety. I had actually tried my hand at writing a new function tep_swf by stripping down the original function and escaping the new function - but I was really making a mess of it and more complicated than it needed to be.

 

sorry, I though u knew what u were doing!!

 

HA HA! There are those days when i think i do, but then there are days like today...... :blush:

 

Hey spooks, thanks for taking the time to help me - I had already spent a day on this and was quite bleary-eyed, and if not for you I would be at it again today.

 

My best to you -

Share this post


Link to post
Share on other sites
sorry, I though u knew what u were doing!!

 

put back your original function, renaming it to tep_image_original

 

then put

 

if (substr($src, -4) == '.swf') return tep_image_original ($src, $alt, $width, $height, $params);

 

at the start of the new function

 

Hmmmm, this is going to need a little tweak -

 

The swf file "thumbs" are showing up just fine now, but on any pages that display them, i get a momentary flash of white and then the page loads. It seems as though ALL the images are getting parsed again. In Firefox, it only seems to occur on pages with swf - and in IE it happens on every page.

 

So close and yet...yet....

 

Any thoughts? Thanks so much!

Share this post


Link to post
Share on other sites
Hmmmm, this is going to need a little tweak -

 

The swf file "thumbs" are showing up just fine now, but on any pages that display them, i get a momentary flash of white and then the page loads. It seems as though ALL the images are getting parsed again. In Firefox, it only seems to occur on pages with swf - and in IE it happens on every page.

 

So close and yet...yet....

 

Any thoughts? Thanks so much!

 

Methinks me has it! :lol:

 

In the OTF tep_image function I removed the tidbit you originally suggested:

if (substr($src, -4) == '.swf') return tep_image_original ($src, $alt, $width, $height, $params);

 

moved it further down - to change this:

 

            // Scale the image if not the original size
           if ($image_size[0] != $width || $image_size[1] != $height) {
               $rx = $image_size[0] / $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 '';
       }
   }

 

to this:

 

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

               if ($rx < $ry) {
                   $width = intval($height / $ratio);
               } else {
                   $height = intval($width * $ratio);
               }
           if (substr($src, -4) == '.swf') $image = '<embed src="' . $src . '"';
            } else {
               $image = '<img src="product_thumb.php?img=' . $src . '&w=' .
               tep_output_string($width) . '&h=' . tep_output_string($height) . '"';
           }

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

 

Initial testing seems to show that it covers all the bases and I don't even need to use the tep_image_original!

 

swf files seem to be resizing/displaying properly, regular images seem to be thumnailing properly, and there doesn't seem to be the white flash of blank page while the images reload.

 

~ Fingers crossed ~

 

Sam, I could have never done it without you giving me that snippet! Thanks a million!

 

Now, I'm still having an issue with IE - it reloads the images on EVERY page and I don't think it has anything to do with the OTF Thumbnailer. I uploaded a stock html_output file and it behaves the same way. I guess that's for another thread.

 

Thank you Sam again - I'll let you know if it blows up!

Share this post


Link to post
Share on other sites
Methinks me has it! :lol:

Aw, gee, I spoke too soon - once I cleared my cache the thumbnails ARE NOT displaying properly - ARGHHH!!

 

I think I'm on the right track though - maybe switching the order....

 

Sam, your original idea worked just fine except for that "iimage reloading thing"

 

OK, I'm gonna go drown my sorrows in a pint of ice cream and come back to this later.....

 

As always, thanks for your time -

Share this post


Link to post
Share on other sites
Aw, gee, I spoke too soon - once I cleared my cache the thumbnails ARE NOT displaying properly - ARGHHH!!

 

I think I'm on the right track though - maybe switching the order....

 

Sam, your original idea worked just fine except for that "iimage reloading thing"

 

OK, I'm gonna go drown my sorrows in a pint of ice cream and come back to this later.....

 

As always, thanks for your time -

 

Ok, I may be drunk with sugar but i think I may really have it this time - I ended up with this modification in the OTC tep_image function:

 

            // Scale the image if not the original size
           if ($image_size[0] != $width || $image_size[1] != $height) {
               $rx = $image_size[0] / $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) . '"';

           if (substr($src, -4) == '.swf') $image = '<embed src="' . tep_output_string($src) . '"';
           }

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

 

It seems to be working for now - I'll let ya know!

 

:blink:

Share this post


Link to post
Share on other sites

Hi, all. I did an install of version 2.4 fix 4, and it works, but now when you click to enlarge the image you get the same image. I saw a post about this earlier, but no fix. Anyone know where the error is?

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