Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

'On The Fly' Auto Thumbnailer using GD Library 2.1


mloeffen

Recommended Posts

In my opinion, there is no need to have the jpeg quality set at 100% as this can result in huge file sizes which can end up with the thumbnail being a larger file size than the original image.

If you want to adjust the jpeg image quality to a more reasonable value, for example 75%, replace all instances of

 

imagejpeg($tmp_img, '', 100);

 

with

 

imagejpeg($tmp_img, '', 75);

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

  • Replies 556
  • Created
  • Last Reply

Top Posters In This Topic

By the sound of things, this is the contribution I need - I've installed it, but I need help getting things to work. Client store has various product photos that are either horizontally or vertically oriented - so pasting onto a common size canvas makes one group or the the other too small. With current small image settings (120x80) the tall group group thumbs are 'squished'. Hoping this is the right contrib for my dilema, and that the group can help me out. Here's where I'm at.

 

Server info:

osC: 2.2-MS2

php: 4.3.11

gd: bundled (2.0.28 compatible)

 

Config info:

Small Image Width: 120

Small Image Height: 80

Calculate Image Size: true

Image Required: true

 

product_thumb.php info:

CONFIG AREA

use_resampling = true

use_truecolor = true

gif_as_jpeg = true

tn_cache = true

r = 255

g = 255

b = 255

allow_larger = false

show_original = true

 

IN THE CODE

Uncommented the $filename and set with full path - (did this after some testing - produces the sames results as when not used)

 

CHMOD=755 (also tried 777 - same results)

Note: when I call this in the browser, I get a small 'Error' text that appears. Changing the text in the string (line 67) and uploading confirmed that this is generated by the php doc, and isn't server generated.

 

-----

 

thumbnails directory info:

Created 'thumbnails' directory in the 'images' directory inside the 'store' directory (osCommerce root) on server - both 'thumbnails' and 'images' are CHMOD=777

 

-----

 

includes/functions/html_output.php info:

Copy / paste to 'Replace your function tep_image code with the code below'

CHMOD=644

 

-----

 

At this point, the functionality of the store is still the same - nothing has blown up, but I'm not getting the desired result either. What did I miss / screw up / forget?

 

TIA for any light you can shed - I'm in south Florida, post Hurricane Wilma, still without power save for my neighbors generator - gettin' tired of spending all my time in the dark.

Link to comment
Share on other sites

In my opinion, there is no need to have the jpeg quality set at 100% as this can result in huge file sizes which can end up with the thumbnail being a larger file size than the original image.

If you want to adjust the jpeg image quality to a more reasonable value, for example 75%, replace all instances of

 

imagejpeg($tmp_img, '', 100);

 

with

 

imagejpeg($tmp_img, '', 75);

 

 

One thing I should add, is that if you are using JPEG source images, and decrease the quality of the thumbnails using the above, then it might be best to save them at 100% quality. This will avoid having them JPEG compressed twice and result in better quality.

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

I am having the same problems as others. Followed installation exactly - did not enable for admin section. Thumbnails directory is empty, no thumbs show on page. Page Icons, stock and custom, do not show as well. I am using osCommerce 2.2 with STS. Help will be appreciated.

Link to comment
Share on other sites

One thing I should add, is that if you are using JPEG source images, and decrease the quality of the thumbnails using the above, then it might be best to save them at 100% quality. This will avoid having them JPEG compressed twice and result in better quality.

Tomjmul,

 

Thanks so much. This was one of those little things that was bugging me for over a year. What I found is that if I set it to 93 it is equivalent to the adobe photoshop "save for web at 72 quality" which is how I save all my jpegs. My images look so much better. :thumbsup:

 

imagejpeg($tmp_img, '', 93);

Link to comment
Share on other sites

For reference, Here is my site.

The pertinent part of product_thumbs.php is

$tn_server_cache = true;
$tn_path = '/catalog/images/thumbnails/';

I have tried nearly all path combinations from http:// to just 'thumbnails' always the same result.

 

GD info:

GD Support enabled

GD Version bundled (2.0.28 compatible)

FreeType Support enabled

FreeType Linkage with freetype

GIF Read Support enabled

GIF Create Support enabled

 

Addition to output_html was re-confirmed, directories are set to correct permissions. I made no changes to the files in the admin directory. Nothing is in the 'thumbnails' directory. All thumbnails are relaced with the dreaded 'red x'. I am really at a loss - I need help

Link to comment
Share on other sites

oblivion77 - Glad that worked out for you.

 

For anyone else, who would like to the ability to alter their thumbnail image quality resulting in *substantially* smaller thumbnail and pop-up filesizes and thus much faster page loading time, below is how to mod the Auto Thumbnail code. After this is done, you will be able to set the output quality from your admin panel (configuration->images) for each of your seperate thumbnail sizes (small, medium, large and also a default)

 

To give you an idea of the difference this can make, one of my pop up images was 45KB before I did this mod. Afterwards, with my quality set to 75% it was only 9KB with very little noticable difference.

 

I will post this in the contribs section for first time installers or those who would prefer a drop in replacement.

 

Step 1 - Execute the following SQL query on your osc database

INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES (3000,'Default image JPEG Quality','DEFAULT_JPEG_QUALITY','75','The default output quality of JPEG thumbnails',4,99,NULL,'2005-01-06 20:24:30',NULL,NULL);
INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES (3001,'Small image JPEG Quality','SMALL_JPEG_QUALITY','80','The output quality of small JPEG thumbnails',4,100,NULL,'2005-01-06 20:24:30',NULL,NULL);
INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES (3002,'Medium image JPEG Quality','MEDIUM_JPEG_QUALITY','90','The output quality of medium JPEG thumbnails',4,101,NULL,'2005-01-06 20:24:30',NULL,NULL);
INSERT INTO configuration (configuration_id, configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, last_modified, date_added, use_function, set_function) VALUES (3003,'Large image JPEG Quality','LARGE_JPEG_QUALITY','75','The output quality of large JPEG thumbnails',4,102,NULL,'2005-01-06 20:24:30',NULL,NULL);

 

Step 2 - Alter the /catalog/includes/functions/html_output.php file as follows:

 

Find:

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

 

Replace with:

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

 

Find:

		$image = '<img src="product_thumb.php?img='.$src.'&w='.
	tep_output_string($width).'&h='.tep_output_string($height).'"';

 

Replace with:

	   //Set the JPEG quality to configuration value if not over-ridden
	if (!tep_not_null($quality)) {
		  $quality = DEFAULT_JPEG_QUALITY;
		  if ($width == SMALL_IMAGE_WIDTH || $height==SMALL_IMAGE_HEIGHT) $quality = SMALL_JPEG_QUALITY;
		  elseif ($width == MEDIUM_IMAGE_WIDTH || $height==MEDIUM_IMAGE_HEIGHT) $quality = MEDIUM_JPEG_QUALITY;
		  elseif ($width == LARGE_IMAGE_WIDTH || $height==LARGE_IMAGE_HEIGHT) $quality = LARGE_JPEG_QUALITY;
	}
	$image = '<img src="product_thumb.php?img='.$src.'&w='.
	tep_output_string($width).'&h='.tep_output_string($height).'&q='.$quality.'"';

 

Step 3 - Alter the /catalog/product_thumb.php file:

 

Find:

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

 

Just AFTER it ADD:

//Has a (valid) quality parameter been provided, if not set to 100%
if (!empty($_GET['q']) && (int)$_GET['q'] > 0 && (int)$_GET['q'] <= 100) $quality = (int)$_GET['q'];
else $quality=100;

 

Find:

global $use404, $tn_browser_cache;

 

Replace with:

global $use404, $tn_browser_cache, $quality;

 

Now replace all instances of:

imagejpeg($src, '', 100);

 

With:

imagejpeg($src, '', $quality);

 

 

If you have the admin side thumnailer installed, just repeat steps 2 & 3 with the admin version of these files (/catalog/includes/functions/html_output.php and /catalog/admin/product_thumbs.php)

 

Lastly, for those of you that do custom design work on your osc store and use the tep_image() function to show graphics, you can now specify an extra (final) quality parameter, which will have the effect of over-riding the quality set in the admin panel.

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

To make the image caching work, without having to manually delete all cached files whenever you change your quality settings try the following:

 

Alter the /catalog/product_thumb.php and /catalog/admin/product_thumb.php files:

 

Find:

if ($tn_server_cache) $filename = modify_tn_path($_GET['img'] .'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.jpg');

 

Replace With:

if ($tn_server_cache) $filename = modify_tn_path($_GET['img'] .'.thumb_'.$_GET['w'].'x'.$_GET['h'].'_'.$quality.'.jpg');

 

Find:

$thumbnail = modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.jpg');

 

Replace with:

$thumbnail = modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'_'.$quality.'.jpg');

 

 

I mentioned in an earlier post that if you use this mod, I think it is best if you save the oringal at 100% quality to avoid them being JPEG compressed twice (once by your graphics software and again by using this thumbnailer.

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

For everyone who is having difficulty with this mod and getting the broken image symbol, or can't use the cache functionality (which it seems is a lot of people if the posts here are anything to go by) try this solution.

 

In /catalog/product_thumb.php:

 

Find:

function modify_tn_path($file)
{
	global $tn_path;

	if ($tn_path=='') return $file;
	else{
			// append the thumbnail-path to the path
			$pathSep = strstr(PHP_OS, "WIN") ? "\\" : "/";;
			$path = reverse_strrchr($file,$pathSep);
			if ($path===false) return $tn_path . $file;
			else return str_replace($path,$path . $tn_path,$file);
		}
}

 

Replace with:

function modify_tn_path($file)
{
global $tn_path;

if ($tn_path=='') return $file;
else{
	// append the thumbnail-path to the path
	$pathSep = strstr(PHP_OS, "WIN") ? "\\" : "/";;
	$path = reverse_strrchr($file,$pathSep);
	if ($path===false) return $tn_path . $file;
	else return str_replace($path,$path . $tn_path,$file);
}
}

 

This changes the functionality of this code to a much more simpler mechanism.

Before where you had to create and chmod a thumbnail directory in every image subdirectory you used, now the script will automatically create and chmod the directories for you if they don't exist.

 

Also all new directories will be created under the root you specify in this line:

$tn_path = 'thumbnails/';

 

This will result in a shadow copy of your image directory under /thumbnails which will contain only the cached thumbnailed versions of the images instead of having them spread all over the place and should fix those broken image problems.

 

Post here whether or not it works for you, so that this mod can be improved for others.

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

Hi All,

 

Please bear with me here. I am a complete noob to osC. I am trying to install the "On the Fly" contrib and I am stuck at step #6, it says in /catalog/includes/functions/html_output.php to replace tep_image function with:

 

// "On the Fly" Auto Thumbnailer using GD Library, servercaching and browsercaching
// 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 = '') { 

 // 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) { 
	$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 (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 am so stuck on where this goes... Below is my code.

<?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
 function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
  return false;
}

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

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

if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height)) ) {
  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)) $image .= ' ' . $parameters;

$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);
 }
?>

If anyone could help me out with this, I'd be eternally greatful!

 

Thanks in advance!

Shannon

Link to comment
Share on other sites

For everyone who is having difficulty with this mod and getting the broken image symbol, or can't use the cache functionality (which it seems is a lot of people if the posts here are anything to go by) try this solution.

 

Post here whether or not it works for you, so that this mod can be improved for others.

 

Hi tomjmul

 

I think there is something not right about your code. The replacement code looks the same as the code to replace.

 

From what you mention this is exactly what I need to implement to get this working. Please repost again.

 

Regards

Aaron

Edited by aarondwyer

Aaron Dwyer

Link to comment
Share on other sites

Little help please.

Stuck on step 6.

I don't have tep_image function in my html output.

 

Here is code for page:

 

<?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 ? 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

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

if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {

return false;

}

 

// alt is added to the img tag even if it is null to prevent browsers from outputting

// the image filename as default

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

 

if (tep_not_null($alt)) {

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

}

 

if ( (CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (empty($width) || empty($height)) ) {

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)) $image .= ' ' . $parameters;

 

$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);

}

?>

 

Where would I repace the code at then?

TIA

Edited by AnnasAttic
Link to comment
Share on other sites

Hi tomjmul

 

I think there is something not right about your code. The replacement code looks the same as the code to replace.

 

From what you mention this is exactly what I need to implement to get this working. Please repost again.

 

Regards

Aaron

 

 

Sorry the replace should be:

 

function modify_tn_path($file)

{

global $tn_path;

 

if ($tn_path=='') return $file;

else{

// append the thumbnail-path to the path

$pathSep = strstr(PHP_OS, "WIN") ? "\\" : "/";;

$path = reverse_strrchr($file,$pathSep);

if ($path===false) {

return $tn_path . $file;

}

else {

if (!file_exists($tn_path. $path)) {

$create_path=$tn_path. $path;

do {

$dir = $create_path;

while (!@mkdir($dir,0777)) {

$dir = dirname($dir);

if ($dir == $pathSep || is_dir($dir))

break;

}

} while ($dir != $create_path);

}

return str_replace($path,$tn_path. $path,$file);

}

}

}

 

I can't get the code tags to do the proper indenting

Edited by tomjmul

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

I have just started working on completely updating this contrib to allow for all the features I have already posted and also image watermaking, text watermarking, framing and brightness/contrast adjustment of thumbnailed images. It should be finished in a day or two.

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

Hello,

I installed the contribution but still can't get the image to show, all I get is the red X. I am a reasonably skilled programmer but for some reason can't get this to work.

 

Here is the configuration info:

osCommerce 2.2-MS2

PHP Version 4.3.11

GD bundled (2.0.28 compatible)

 

define('DIR_WS_IMAGES', 'images/');

define('DIR_FS_CATALOG', '/home/jacobtim/jacobtime-www/osc_backup/');

 

 

The URL: http://www.jacobtime.com/osc_backup/

please select any categoty from the left menu

 

In "product_thunb.php" I replaced the 'DIR_FS_CATALOG' with 'DIR_WS_IMAGES', since this seems to be the correct image path.

 

I wrote a simple script to test the image path:

 

----------------------------------------------------------

<?php
include_once("includes/configure.php");

$filename = '0309661.jpg';

if (file_exists(DIR_WS_IMAGES . $filename)){
 echo 'path= '.DIR_WS_IMAGES . $filename;
 echo '<br>time= '.filemtime(DIR_WS_IMAGES . $filename);
}else{
echo 'did not find: '.DIR_WS_IMAGES . $filename;
}
?>

--------------------------------------------------------

 

URL to the test script: http://www.jacobtime.com/osc_backup/test.php

 

product_thumb.php settings:

$use_resampling = false;
$use_truecolor = false;
$gif_as_jpeg = false;
$tn_server_cache = false;
$tn_path = 'thumbnails/';
$tn_browser_cache = true;
$use404 = true;
$r = 255; // Red color value (0-255)
$g = 255; // Green color value (0-255)
$b = 255; // Blue color value (0-255)
$allow_larger = false;
$show_original = true;

 

I think it is a path issue and the images seem to size correctly, any help would be appreciated :)

Link to comment
Share on other sites

Tried the fix Tom posted and images won't show with changes to product_thumb.php, but still npt cachig.

Any suggestions?

TIA

 

 

Does the thumbnail directory exist and is it chmodded to 777?

 

If your root directory is not chmodded to 777 this script cannot make the first directory which all others will be contained in, if you create this first directory manually, the script should be able to create any others needed to shadow your image subdirectories

 

Hope that makes sense.

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

Just finsihed a new version of this contrib which will have some extra features such as watermarking, buttonize and framing of thumbnails and quality adjustment etc. It will also have a more reliable (I hope) caching mechanism.

 

I am doing a bit of testing and will release it tomorrow.

 

In the meantime, if you want to see an example of some of the output go to http://www.celtware.com/autothumb.htm

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

Just finsihed a new version of this contrib which will have some extra features such as watermarking, buttonize and framing of thumbnails and quality adjustment etc. It will also have a more reliable (I hope) caching mechanism.

 

I am doing a bit of testing and will release it tomorrow.

 

In the meantime, if you want to see an example of some of the output go to http://www.celtware.com/autothumb.htm

 

That looks bloody brilliant. Can't wait.

 

My local development box (Windows OS) still can't get the images to display without doing this

 

$tn_server_cache = false;

 

Even with Tom's modified function modify_tn_path($file)

 

Oh well. As long as it works on the server (I hope it still does)

 

Thanks

Aaron

Aaron Dwyer

Link to comment
Share on other sites

Hello,

I installed the contribution but still can't get the image to show, all I get is the red X. I am a reasonably skilled programmer but for some reason can't get this to work.

 

Here is the configuration info:

osCommerce 2.2-MS2

PHP Version 4.3.11

GD bundled (2.0.28 compatible)

 

define('DIR_WS_IMAGES', 'images/');

define('DIR_FS_CATALOG', '/home/jacobtim/jacobtime-www/osc_backup/');

The URL: http://www.jacobtime.com/osc_backup/

please select any categoty from the left menu

 

In "product_thunb.php" I replaced the 'DIR_FS_CATALOG' with 'DIR_WS_IMAGES', since this seems to be the correct image path.

 

I wrote a simple script to test the image path:

 

----------------------------------------------------------

<?php
include_once("includes/configure.php");

$filename = '0309661.jpg';

if (file_exists(DIR_WS_IMAGES . $filename)){
 echo 'path= '.DIR_WS_IMAGES . $filename;
 echo '<br>time= '.filemtime(DIR_WS_IMAGES . $filename);
}else{
echo 'did not find: '.DIR_WS_IMAGES . $filename;
}
?>

--------------------------------------------------------

 

URL to the test script: http://www.jacobtime.com/osc_backup/test.php

 

product_thumb.php settings:

$use_resampling = false;
$use_truecolor = false;
$gif_as_jpeg = false;
$tn_server_cache = false;
$tn_path = 'thumbnails/';
$tn_browser_cache = true;
$use404 = true;
$r = 255; // Red color value (0-255)
$g = 255; // Green color value (0-255)
$b = 255; // Blue color value (0-255)
$allow_larger = false;
$show_original = true;

 

I think it is a path issue and the images seem to size correctly, any help would be appreciated :)

 

Ok I managed to fix the problem of the image not showing by changing the path variable, to make it seperate from any existing configuration variables I created a new variable in the configure.php file:

define('DIR_WS_IMAGES_THUMB', '');

 

and replaced all the 'DIR_FS_CATALOG' in "product_thunb.php" with the new variable 'DIR_WS_IMAGES_THUMB', I suspect that if your image is not showing than you also have the wrong path set.

Link to comment
Share on other sites

Ok I managed to fix the problem of the image not showing by changing the path variable, to make it seperate from any existing configuration variables I created a new variable in the configure.php file:

define('DIR_WS_IMAGES_THUMB', '');

 

and replaced all the 'DIR_FS_CATALOG' in "product_thunb.php" with the new variable 'DIR_WS_IMAGES_THUMB', I suspect that if your image is not showing than you also have the wrong path set.

 

I am a little confused by what you mean here. As far as I can see the product_thumb.php script does not contain any references to defined constants from the configuration.php file

OSC Image Magic

On-the-fly thumbnails, watermarks and image processing

Link to comment
Share on other sites

Just finsihed a new version of this contrib which will have some extra features such as watermarking, buttonize and framing of thumbnails and quality adjustment etc. It will also have a more reliable (I hope) caching mechanism.

 

I am doing a bit of testing and will release it tomorrow.

 

In the meantime, if you want to see an example of some of the output go to http://www.celtware.com/autothumb.htm

I'm really looking forward to your update! I have been struggling with my thumbs this weekend. I installed Automatic Thumbnail Creator some time ago but now discovered that it cannot create PNGs with transparent background. After playing around with the image_ functions I got it to work in Firefox but not in IE, for some reason, the images display with a black background. Anyway, so I decided to get rid of that one and try a better, more advanced contrib. That's when I came across this thread, so now I will wait until you release your update. Many thanks in advance :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...