Jump to content
Sign in to follow this  
allymacneil

Automatic Thumbnail /contributions,1484

Recommended Posts

Hi there, up untill recently I had been using the:

"On the Fly Thumbnailer" using PHP GD Graphics Library by Nathan Welch (v1.5)

Used in conjunction with product_thumb.php thumbnail generator.

 

This was producing good results but my page loads where slower than I wanted and my host kept telling me that if an extra php file had to be called 20 times a category page was loaded (or how ever many thumbnails there where) it was going to slow things down.

 

Took the plunge this evening and installed Automatic Thumbnail

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

 

It was faster but the thumbnails where awful. By this point I'd understood a little more what was going on, got back in touch with my host and he gave me the idea to use the code from the on the fly thumbnailer to calulate the width and height for the thumbnails which I did and things are now much better.

 

Posting the change here, if people want to comment on how well this works for them I will add it as a new package to the contrib so people trying it for the first time can benefit.

 

in catalog/includes/functions/html_output.php

 

find

	// 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 larger than the set width or height
					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).'"';
		}

 

replace with

		if ((CONFIG_CALCULATE_IMAGE_SIZE == 'true' && $src != DIR_WS_IMAGES . 'pixel_black.gif' && $src != DIR_WS_IMAGES . 'pixel_trans.gif' && $src != DIR_WS_IMAGES . 'pixel_silver.gif' )) 
	{
		$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 larger than the set width or height
		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); 
			} 

			$src=thumbimage(DIR_FS_CATALOG . '/' .$src, $width, $height, 1, 1, DIR_FS_CATALOG . '/' . DIR_WS_IMAGES . 'imagecache');

			if ((($image_size[1]/$height) > ($image_size[0]/$width) ) && $height>0)
			{
				$width=ceil(($image_size[0]/$image_size[1])* $height);
			} 
			elseif ($width>0) 
			{
				$height=ceil($width/($image_size[0]/$image_size[1]));
			}
		}
	}

 

 

That should be it, wanting to test it here before uploading to the main contrib area

 

Results using on the fly thumbnailer with product_thumb.php

Family category -> Parse time = approx 0.055 - 0.60 -> page loads in approx 900ms (using firebug plugin for fire fox)

All Products -> Parse Time = approx 0.110 - 0.120 - > Page loads in approx 4.3 secs

 

Results using Automatic Thumbnail with change above

Family category -> Parse 0.078 -> page loads approx 700ms

All Products -> Parse 0.370 - 0.390 -> page loads in 2.28 secs

 

parse times a little longer but the pages are loading quicker

 

HTH,

Ally :thumbsup:


"Know that this is your God, who could not consent to send anyone else to save you, but would come himself that he might gain for himself all your love." St Alphonsus Ligouri

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  

×