Jump to content
Sign in to follow this  
kidtortuga

'On the Fly' Auto Thumbnailer in admin

Recommended Posts

Hi all,

 

My apologies if this has been addressed before, but I couldn't find it in a search. I installed the Auto Thumbnailer contrib, and it seems to work great, but only in the catalog, and not in the admin tool preview.

 

Is this as expected, or is something amiss? If so, is there an easy way to fix it? I've tried modifying the tep_image function in the admin directory, but no luck. I thought somebody might have solved this problem already.

 

Thanks.

Share this post


Link to post
Share on other sites

I figured it out, will post it to "On the fly" thumblainer contribution later,

 

If you followed the instructions:

1) You need to change you tep_image() function definition located in admin/includes/functions/html_output.php the same way you did for includes/functions/html_output.php

 

2) You need to change your configure file for admin located at admin/includes/configure.php

 

Code:

 

define('DIR_WS_CATALOG_IMAGES', DIR_WS_CATALOG . 'images/'); // old line

 

to

 

define('DIR_WS_CATALOG_IMAGES', '../images/'); //new line

 

Note: this done for the reason that getimagesize() might fail to work inside modified tep_image() function, especially in the case of SSL protected areas

I will still need advice of Community on doing this in terms of possible security problems.

 

3) Finally you need to !!!!! VERY IMPORTANT !!!! copy "product_thumb.php" into admin folder

 

READY TO ROCK AND ROLL

Share this post


Link to post
Share on other sites

Hi,

I just installed it for my Admin but i have not the SSL function on my Web site.

2) You need to change your configure file for admin located at admin/includes/configure.php

 

Code:

 

CODEdefine('DIR_WS_CATALOG_IMAGES', DIR_WS_CATALOG . 'images/'); // old line

 

to

 

CODEdefine('DIR_WS_CATALOG_IMAGES', '../images/'); //new line

If i changed the above code in the configure.php of admin and check the Review in Admin(Admin>Catalog>Reviews) ,i found that the picture which under the "Rating" column cannot be shown. Also if i click to continue to peview product, the product's picture also cannot be shown on reviews.php page.

Because of it, i have not do any change in configure.php file. Is it OK?

 

Thanks,

Anita.


Welcome to vist my Site:

Anita.

Share this post


Link to post
Share on other sites
Hi,

I just installed it for my Admin but i have not the SSL function on my Web site.

 

If i changed the above code in the configure.php of admin and check the Review in Admin(Admin>Catalog>Reviews) ,i found that the picture which under the "Rating" column cannot be shown. Also if i click to continue to peview product, the product's picture also cannot be shown on reviews.php page.

Because of it, i have not do any change in configure.php file. Is it OK?

 

Thanks,

Anita.

 

Double dot just steps down a folder, standard unix feature

Don't worry it'll still work. Try and tell us the results

Share this post


Link to post
Share on other sites

So far is ok, nothing abnormal is found.

anita.

 

Double dot just steps down a folder, standard unix feature

Don't worry it'll still work. Try and tell us the results


Welcome to vist my Site:

Anita.

Share this post


Link to post
Share on other sites
3) Finally you need to !!!!! VERY IMPORTANT !!!! copy "product_thumb.php" into admin folder

 

READY TO ROCK AND ROLL

 

hi, im trying to instal your script, but i dont know ware to find the "product_thumb.php" file :S

 

if someone could point me to that file i would love it! thanks

Share this post


Link to post
Share on other sites

Anyone know, is it possible to change the default file permissions for the cached files. They are using 600 but i really need 644, as my ftp program won't read the files

Share this post


Link to post
Share on other sites

ok odd issue, if I have a width set in admin it works on my images but the desplay sizes are VERY messed up. if everything is set to null then it doesn't seem to work at all. my site is at http://www.vssales.net if you wanna see wahat i mean. im posting both my files here so if anyone knows whats the issue please let me know. if i don't use the thumbnail cont the images range from 50k - 150k so i kinda need it lol thanks for anyone who helps out

 

 

product thumb

 

<?php
// "On the Fly Thumbnailer" using PHP GD Graphics Library by Nathan Welch (v1.5)
// Scales product images dynamically, resulting in smaller file sizes, and keeps
// proper image ratio.  Used in conjunction with modified tep_image in html_output.php
//
// CONFIGURATION SETTINGS
//
// Use Resampling? Set the value below to true to generate resampled thumbnails
// resulting in smoother-looking images.  Not supported in GD ver. < 2.01
$use_resampling = true;
//
// Create True Color Thumbnails? Better quality overall but set to false if you
// have GD version < 2.01 or if creating transparent thumbnails.
$use_truecolor = false;
//
// Output GIFs as JPEGS? Set this option to true if you have GD version > 1.6
// and want to output GIF thumbnails as JPGs instead of GIFs or PNGs.  Note that your
// GIF transparencies will not be retained in the thumbnail if you output them
// as JPGs. If you have GD Library < 1.6 with GIF create support, GIFs will
// be output as GIFs. Set the "matte" color below if setting this option to true.
$gif_as_jpeg = false;
//
// Define RGB Color Value for background matte color if outputting GIFs as JPEGs
// Example: white is r=255, b=255, g=255; black is r=0, b=0, g=0; red is r=255, b=0, g=0;
$r = 255; // Red color value (0-255)
$g = 255; // Green color value (0-255)
$b = 255; // Blue color value (0-255)
//
// END CONFIGURATION SETTINGS

// Get the size of the image
$image = @getimagesize($_GET['img']);

// Do not output if get values are larger than orig image
if ($_GET['w'] > $image[0] || $_GET['h'] > $image[1])
   return;

// Create appropriate image header
if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg)) {
   header('Content-type: image/jpeg');
} elseif ($image[2] == 1 && function_exists(imagegif)) {
   header('Content-type: image/gif');
}  elseif ($image[2] == 3 || $image[2] == 1) {
   header('Content-type: image/png');
} 

// Create a new, empty image based on settings
if (function_exists(imagecreatetruecolor) && $use_truecolor)
   $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']);
} 

// Scale the image based on settings
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)) {
   imagejpeg($tmp_img);
} elseif ($image[2] == 1 && function_exists(imagegif)) {
   imagegif($tmp_img);
} elseif ($image[2] == 3 || $image[2] == 1) {
   imagepng($tmp_img);
}

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

?>

Share this post


Link to post
Share on other sites

and the html_output

 

<?php
/*
 $Id: html_output.php,v 1.56 2003/07/09 01:15:48 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

////
// The HTML href link wrapper function
 function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
   global $request_type, $session_started, $SID;

   if (!tep_not_null($page)) {
     die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine the page link!<br><br>');
   }

   if ($connection == 'NONSSL') {
     $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
   } elseif ($connection == 'SSL') {
     if (ENABLE_SSL == true) {
       $link = HTTPS_SERVER . DIR_WS_HTTPS_CATALOG;
     } else {
       $link = HTTP_SERVER . DIR_WS_HTTP_CATALOG;
     }
   } else {
     die('</td></tr></table></td></tr></table><br><br><font color="#ff0000"><b>Error!</b></font><br><br><b>Unable to determine connection method on a link!<br><br>Known methods: NONSSL SSL</b><br><br>');
   }

   if (tep_not_null($parameters)) {
     $link .= $page . '?' . tep_output_string($parameters);
     $separator = '&';
   } else {
     $link .= $page;
     $separator = '?';
   }

   while ( (substr($link, -1) == '&') || (substr($link, -1) == '?') ) $link = substr($link, 0, -1);

// Add the session ID when moving from different HTTP and HTTPS servers, or when SID is defined
   if ( ($add_session_id == true) && ($session_started == true) && (SESSION_FORCE_COOKIE_USE == 'False') ) {
     if (tep_not_null($SID)) {
       $_sid = $SID;
     } elseif ( ( ($request_type == 'NONSSL') && ($connection == 'SSL') && (ENABLE_SSL == true) ) || ( ($request_type == 'SSL') && ($connection == 'NONSSL') ) ) {
       if (HTTP_COOKIE_DOMAIN != HTTPS_COOKIE_DOMAIN) {
         $_sid = tep_session_name() . '=' . tep_session_id();
       }
     }
   }

   if ( (SEARCH_ENGINE_FRIENDLY_URLS == 'true') && ($search_engine_safe == true) ) {
     while (strstr($link, '&&')) $link = str_replace('&&', '&', $link);

     $link = str_replace('?', '/', $link);
     $link = str_replace('&', '/', $link);
     $link = str_replace('=', '/', $link);

     $separator = '?';
   }

   if (isset($_sid)) {
     $link .= $separator . $_sid;
   }

   return $link;
 }

////
// The HTML image wrapper function
// "On the Fly Thumbnailer" using PHP GD Graphics Library by Nathan Welch (v1.5)
// 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 = '50%') { 

   // 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; 	 
 }	

   // 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).'"';
           }
     
       } 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 ($params != '') { 
       $image .= ' ' . $params; 
   } 

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

   $image .= '>';  
 
   return $image; 
} 	 


////
// The HTML form submit button wrapper function
// Outputs a button in the selected language
 function tep_image_submit($image, $alt = '', $parameters = '') {
   global $language;

   $image_submit = '<input type="image" src="' . tep_output_string(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image) . '" border="0" alt="' . tep_output_string($alt) . '"';

   if (tep_not_null($alt)) $image_submit .= ' title=" ' . tep_output_string($alt) . ' "';

   if (tep_not_null($parameters)) $image_submit .= ' ' . $parameters;

   $image_submit .= '>';

   return $image_submit;
 }

////
// Output a function button in the selected language
 function tep_image_button($image, $alt = '', $parameters = '') {
   global $language;

   return tep_image(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image, $alt, '', '', $parameters);
 }

////
// Output a separator either through whitespace, or with an image
 function tep_draw_separator($image = 'pixel_black.gif', $width = '100%', $height = '1') {
   return tep_image(DIR_WS_IMAGES . $image, '', $width, $height);
 }

////
// Output a form
 function tep_draw_form($name, $action, $method = 'post', $parameters = '') {
   $form = '<form name="' . tep_output_string($name) . '" action="' . tep_output_string($action) . '" method="' . tep_output_string($method) . '"';

   if (tep_not_null($parameters)) $form .= ' ' . $parameters;

   $form .= '>';

   return $form;
 }

////
// Output a form input field
 function tep_draw_input_field($name, $value = '', $parameters = '', $type = 'text', $reinsert_value = true) {
   $field = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';

   if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {
     $field .= ' value="' . tep_output_string(stripslashes($GLOBALS[$name])) . '"';
   } elseif (tep_not_null($value)) {
     $field .= ' value="' . tep_output_string($value) . '"';
   }

   if (tep_not_null($parameters)) $field .= ' ' . $parameters;

   $field .= '>';

   return $field;
 }

////
// Output a form password field
 function tep_draw_password_field($name, $value = '', $parameters = 'maxlength="40"') {
   return tep_draw_input_field($name, $value, $parameters, 'password', false);
 }

////
// Output a selection field - alias function for tep_draw_checkbox_field() and tep_draw_radio_field()
 function tep_draw_selection_field($name, $type, $value = '', $checked = false, $parameters = '') {
   $selection = '<input type="' . tep_output_string($type) . '" name="' . tep_output_string($name) . '"';

   if (tep_not_null($value)) $selection .= ' value="' . tep_output_string($value) . '"';

   if ( ($checked == true) || ( isset($GLOBALS[$name]) && is_string($GLOBALS[$name]) && ( ($GLOBALS[$name] == 'on') || (isset($value) && (stripslashes($GLOBALS[$name]) == $value)) ) ) ) {
     $selection .= ' CHECKED';
   }

   if (tep_not_null($parameters)) $selection .= ' ' . $parameters;

   $selection .= '>';

   return $selection;
 }

////
// Output a form checkbox field
 function tep_draw_checkbox_field($name, $value = '', $checked = false, $parameters = '') {
   return tep_draw_selection_field($name, 'checkbox', $value, $checked, $parameters);
 }

////
// Output a form radio field
 function tep_draw_radio_field($name, $value = '', $checked = false, $parameters = '') {
   return tep_draw_selection_field($name, 'radio', $value, $checked, $parameters);
 }

////
// Output a form textarea field
 function tep_draw_textarea_field($name, $wrap, $width, $height, $text = '', $parameters = '', $reinsert_value = true) {
   $field = '<textarea name="' . tep_output_string($name) . '" wrap="' . tep_output_string($wrap) . '" cols="' . tep_output_string($width) . '" rows="' . tep_output_string($height) . '"';

   if (tep_not_null($parameters)) $field .= ' ' . $parameters;

   $field .= '>';

   if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {
     $field .= stripslashes($GLOBALS[$name]);
   } elseif (tep_not_null($text)) {
     $field .= $text;
   }

   $field .= '</textarea>';

   return $field;
 }

////
// Output a form hidden field
 function tep_draw_hidden_field($name, $value = '', $parameters = '') {
   $field = '<input type="hidden" name="' . tep_output_string($name) . '"';

   if (tep_not_null($value)) {
     $field .= ' value="' . tep_output_string($value) . '"';
   } elseif (isset($GLOBALS[$name])) {
     $field .= ' value="' . tep_output_string(stripslashes($GLOBALS[$name])) . '"';
   }

   if (tep_not_null($parameters)) $field .= ' ' . $parameters;

   $field .= '>';

   return $field;
 }

////
// Hide form elements
 function tep_hide_session_id() {
   global $session_started, $SID;

   if (($session_started == true) && tep_not_null($SID)) {
     return tep_draw_hidden_field(tep_session_name(), tep_session_id());
   }
 }

////
// Output a form pull down menu
 function tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false) {
   $field = '<select name="' . tep_output_string($name) . '"';

   if (tep_not_null($parameters)) $field .= ' ' . $parameters;

   $field .= '>';

   if (empty($default) && isset($GLOBALS[$name])) $default = stripslashes($GLOBALS[$name]);

   for ($i=0, $n=sizeof($values); $i<$n; $i++) {
     $field .= '<option value="' . tep_output_string($values[$i]['id']) . '"';
     if ($default == $values[$i]['id']) {
       $field .= ' SELECTED';
     }

     $field .= '>' . tep_output_string($values[$i]['text'], array('"' => '"', '\'' => ''', '<' => '<', '>' => '>')) . '</option>';
   }
   $field .= '</select>';

   if ($required == true) $field .= TEXT_FIELD_REQUIRED;

   return $field;
 }

////
// Creates a pull-down list of countries
 function tep_get_country_list($name, $selected = '', $parameters = '') {
   $countries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT));
   $countries = tep_get_countries();

   for ($i=0, $n=sizeof($countries); $i<$n; $i++) {
     $countries_array[] = array('id' => $countries[$i]['countries_id'], 'text' => $countries[$i]['countries_name']);
   }

   return tep_draw_pull_down_menu($name, $countries_array, $selected, $parameters);
 }
?>

Share this post


Link to post
Share on other sites

oh btw the line hat reads:

 

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

 

in the code i posted is accually

 

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

 

 

sry bout that, i was playing with it

Share this post


Link to post
Share on other sites

Ok fix my issue, i accually have to put 100 and 100 in the with and height in the admin images panel. thanks anyway, i'd del my prior posts if i could

Share this post


Link to post
Share on other sites

Hi there,

 

I've got the mod to work fine here. Thanks :D

 

Trying to install the admin part though and not sure where to put it exactly. Somebody please fill me in. MTIA.

 

PS: Would be great to have a modding standard like phpbb. I'm writing my own mods/hacks using that prooven method. But that's a whole different topic ;)

 

Axel.

Share this post


Link to post
Share on other sites

I installed this mod and it works great on my product images but does not thumbnail my manufacturers images in the Manufacturers Info box. Any idea's???

Share this post


Link to post
Share on other sites

Another person having problems.

 

Installed the mod and was pretty delighted to see all my images a reasonable size.

 

However:

As soon as I start to browse, it refuses to reload the thumbs. It just leaves me with placeholders as it tries to load them.. Obviously, it had resized everything from cache, but wasn't able to make a new cache of smaller sized images.. It's linking to images such as:

/product_thumb.php?img=images/blkslvdragontights[2].jpg&w=94&h=125

 

 

The actual real images are fine though, if I browse through and click on hte "thumbnail" to enlarge.

 

This is pretty frustrating. It's the one contriib I've used out of all of them that's actually showed some promise and it's still flopped out on me. hehe

 

Have a look for yourself at _my site_ and see what you think. I'm a tad confused about it all.

 

I have not installed the admin part.. Wanted to see if the basic setup worked first. I'm using a zip called "OnTheFly_GDThumbs-w-cache_1_5_1". This is the version installed.

 

Cheers,

Steve.

 

Cheers,

S.

Share this post


Link to post
Share on other sites

First of all a great contribution - Thanks!

 

Here is my problem.

 

I have my product images stored in another folder /path/to/your/images/newfolder/

 

to enable this, my images are being stored in the database as "newfolder/image.jpg"

 

I am caching my images. The thumbnails are being successfully created in the DEFAULT catalog/images/ folder. Now when the cached images are being called, I get the following error:

 

PHP Warning: imagejpeg(): Unable to open 'images/newfolder/image.jpg.thumb_100x86.jpg' for writing in /path/....../catalog/product_thumb.php on line 182

 

What's happening is that imagejpeg() is trying to display the cached thumbnail from the "newfolder/" rather than from where it is being cached from. Is there a way I can correct this.

 

Thanks for all your help,

Share this post


Link to post
Share on other sites

I know this is older so I hope someone sees this question. I am just wanting to know what contrib I should use in conjuction with this one so that I can have multiple images. I want to make sure it works with this contribution of course so I thought someone might be able to help out.

Thanks,

Dingo

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  

×