Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Sign in to follow this  
boltz

On the Fly' Auto Thumbnailer using GD Library

Recommended Posts

i have installed this mod and it worked and all, but there is one issue i noticed that happens after installing and modifying the html_output.php file

 

if you have any product or picture names with ' in the name (IE. it's we're etc) only a thumbnail shows in the category view, but there is no picture displayed with(click to enlarge) on the product_info.php page once you click on the product to view the description

 

any ideas? can other people using this mod test this out and let me know what you find

 

THANKS

 

PS, if i swap the html_output.php back to original the pic shows again regardless of if the product name has an ' (eg. it's or we're)

Share this post


Link to post
Share on other sites

i have found a possible fix, it seems to work when i modify 2 lines of code from the GD mod

 

1st change (near top of mod code)

new code

    $image = '<img src="' . $src . '" border="0" alt=" ' . $alt . '  " title=" ' . $alt . ' "';

 

Old code

$image = '<img src="' . $src . '" border="0" alt=" ' . htmlspecialchars(StripSlashes($alt)) . '  " title=" ' . htmlspecialchars(StripSlashes($alt)) . ' "';

 

 

 

2nd change (near bottom of mod code)

 

New code

// Generate thumbnail on the fly

$image = '<img src="product_thumb.php?img='.$src.'&w='.intval($width).'&h='.intval($height).'" border="0" alt=" ' . $alt . ' " title=" ' . $alt . ' "';

 

Original code

// Generate thumbnail on the fly

$image = '<img src="product_thumb.php?img='.$src.'&w='.intval($width).'&h='.intval($height).'" border="0" alt=" ' . htmlspecialchars(StripSlashes($alt)) . ' " title=" ' . htmlspecialchars(StripSlashes($alt)) . ' "';

 

 

can anyone shead any light on what causes this to happen, why did this fix it, and if this is the proper way to fix this issue. Preferably the mod author could answer me if this is a good way to fix my problem.

 

I have tested with same result on a fresh 2.2ms2

 

Thanks

Share this post


Link to post
Share on other sites

Thanks for pointing that out, boltz. I had noticed the odd pop-up image not coming up, but couldn't determine the common factor - which is the presence of an apostrophe in the product name.

 

The reason this causes the pop-up image not to appear is that osC (for reasons I don't completely understand) uses a Javascript document.write to output the picture and pop-up window link (if Javascript is enabled). If the apostrophes are not properly escaped with a backslash, it produces invalid JS code, and thus the image/pop-up link is not written to the page via the Javascript.

 

The code you wrote will work, but I think reintroduces the escaped backslash into the alt(?) of non-JS browsers.

 

Below is a modified tep_image function you can use which makes use of the tep_output_string to take care of that... It's also slightly cleaned up with respect to the "dont_calculate" variable and the intval check/modifiers were removed.

 

If it works out for ya, let me know and I'll post version 1.1? to the Contrib sections.

 

// Modified tep_image function to keep proper ratio and use GD Library (in conjunction
// with product_thumb.php for image resizing. Requires PHP GD Image Library version 2+
function tep_image($src, $alt = '', $width = '', $height = '', $params = '') { 

   if (($src == '' || $src == 'images/') && IMAGE_REQUIRED == 'false') { 
       return; 
   } 

   $image = '<img src="' . $src . '" border="0" alt=" ' . tep_output_string($alt) . '  " title=" ' . tep_output_string($alt) . ' "';

   if (strstr($width,'%') == false || strstr($height,'%') == false) { 
       $dont_calculate = 0; 
   } else {
       $dont_calculate = 1; 	 
 }	

   if (CONFIG_CALCULATE_IMAGE_SIZE && (!$width || !$height) && !$dont_calculate) { 

       if ($image_size = @getimagesize($src)) { 

           if (!$width && $height) { 
               $ratio = $height / $image_size[1]; 
               $width = $image_size[0] * $ratio; 
           } elseif ($width && !$height) { 
               $ratio = $width / $image_size[0]; 
               $height = $image_size[1] * $ratio; 
           } elseif (!$width && !$height) { 
               $width = $image_size[0]; 
               $height = $image_size[1]; 
           } 
       } elseif (IMAGE_REQUIRED == 'false') { 

       return ''; 
       } 
   } 

   if (CONFIG_CALCULATE_IMAGE_SIZE && !$dont_calculate) { 

       if ($image_size = @getimagesize($src)) { 

           $ratio = $image_size[1] / $image_size[0]; // real ratio 
     
     $orig_width = $image_size[1];
     $orig_height = $image_size[0];

           // do we need scaling 
           if ($image_size[0] > $width || $image_size[1] > $height) { 
               $rx = $image_size[0] / $width; 
               $ry = $image_size[1] / $height; 

               if ($rx < $ry) { 
                   $width = $height / $ratio; 
               } else { 
                   $height = $width * $ratio; 
               } 
                       
               // Generate thumbnail on the fly
       $image = '<img src="product_thumb.php?img='.$src.'&w='.tep_output_string($width).'&h='.tep_output_string($height).'" border="0" alt=" ' . tep_output_string($alt) . ' " title=" ' . tep_output_string($alt) . ' "';
        
           }
       } 
   } 

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

   if ($params != '') { 
       $image .= ' ' . $params; 
   } 

   $image .= '>'; 

   return $image; 
}


** Please do not PM with personal support requests (even if offering "payment"). Thank you.

Share this post


Link to post
Share on other sites

thanks for the quick response.

 

 

That revised version does seem to work, all though i havent tested it extensively.

 

i couldnt say if it does work or not with out java enabled etc...

 

I had time to kill so i compared some code and came up with the changes i made and it fixed it but whatever i did was done blindly.

 

any way if i notice anything else i will let you know

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  

×