Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

'On the Fly' Auto Thumbnailer using GD Library


Guest

Recommended Posts

Hi Nate! :)

 

Yes...I still have some kind of problem with the product listing page after install....

 

It interferes with the "pixel black" and also the tooltip/bubbles that affect the subcategory names, etc. Probably something minor...could you take a look at my code below...and let me know what needs correcting? We're newbies....Thanks....

 

First...take a look here: http://www.shopabundle.com/default.php/cPath/37_64

 

Code (from html_output.php) below:

 

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

 

 

<?php

/*

$Id: html_output.php,v 1.49 2003/02/11 01:31:02 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

////

// Parse the data used in the html tags to ensure the tags will not break

function tep_parse_input_field_data($data, $parse) {

return strtr(trim($data), $parse);

}

 

////

// The HTML href link wrapper function

function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {

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_CATALOG;

} elseif ($connection == 'SSL') {

if (ENABLE_SSL == true) {

$link = HTTPS_SERVER . DIR_WS_CATALOG;

} else {

$link = HTTP_SERVER . DIR_WS_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 . '?' . $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 HTTP and HTTPS servers or when SID is defined

if ( (ENABLE_SSL == true ) && ($connection == 'SSL') && ($add_session_id == true) ) {

$sid = tep_session_name() . '=' . tep_session_id();

} elseif ( ($add_session_id == true) && (tep_not_null(SID)) ) {

$sid = SID;

}

// (( ADD ADDITIONAL SPIDERS HERE WHEN NEEDED))

$spiders = array("MICROSOFT-GLOBAL-NET", "MSFTP-ARIN", "ZM39-ARIN", "msnbot", "YahooSeeker/1.1", "yahooseeker", "slurp", "slurp/si", "[email protected]", "Slurp", "[email protected]", "INKTOMI", "INKT", "inkt", "inktomi", "inktomisearch.com");

foreach($spiders as $Val) {

if (ereg($Val, strtolower($_SERVER["HTTP_USER_AGENT"]))) {

// Edit out one of these as necessary depending upon your version of html_output.php

//$sess = NULL;

$sid = NULL;

break;

}

}

 

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 = '', $params = '') {

 

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

return;

}

 

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

 

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

$dont_calculate = 1;

}

 

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

 

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='.intval($width).'&h='.intval($height).'" border="0" alt=" ' . htmlspecialchars(StripSlashes($alt)) . ' "';

 

} else {

$rx = $image_size[0] / $width;

$ry = $image_size[1] / $height;

 

if ($rx < $ry) {

$width = $height / $ratio;

} else {

$height = $width * $ratio;

}

 

}

}

}

 

if ( ($width) && ($height) ) {

$image .= ' width="' . intval($width) . '" height="' . intval($height) . '"';

}

 

if ($params != '') {

$image .= ' ' . $params;

}

 

$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_parse_input_field_data(DIR_WS_LANGUAGES . $language . '/images/buttons/' . $image, array('"' => '"')) . '" alt="' . tep_parse_input_field_data($alt, array('"' => '"')) . '"';

 

if (tep_not_null($alt)) $image_submit .= ' title=" ' . tep_parse_input_field_data($alt, array('"' => '"')) . ' "';

 

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_parse_input_field_data($name, array('"' => '"')) . '" action="' . tep_parse_input_field_data($action, array('"' => '"')) . '" method="' . tep_parse_input_field_data($method, array('"' => '"')) . '"';

 

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_parse_input_field_data($type, array('"' => '"')) . '" name="' . tep_parse_input_field_data($name, array('"' => '"')) . '"';

 

if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {

$field .= ' value="' . tep_parse_input_field_data($GLOBALS[$name], array('"' => '"')) . '"';

} elseif (tep_not_null($value)) {

$field .= ' value="' . tep_parse_input_field_data($value, array('"' => '"')) . '"';

}

 

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_parse_input_field_data($type, array('"' => '"')) . '" name="' . tep_parse_input_field_data($name, array('"' => '"')) . '"';

 

if (tep_not_null($value)) $selection .= ' value="' . tep_parse_input_field_data($value, array('"' => '"')) . '"';

 

if ( ($checked == true) || ($GLOBALS[$name] == 'on') || ( (isset($value)) && ($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_parse_input_field_data($name, array('"' => '"')) . '" wrap="' . tep_parse_input_field_data($wrap, array('"' => '"')) . '" cols="' . tep_parse_input_field_data($width, array('"' => '"')) . '" rows="' . tep_parse_input_field_data($height, array('"' => '"')) . '"';

 

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

 

$field .= '>';

 

if ( (isset($GLOBALS[$name])) && ($reinsert_value == true) ) {

$field .= $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_parse_input_field_data($name, array('"' => '"')) . '" value="';

 

if (tep_not_null($value)) {

$field .= tep_parse_input_field_data($value, array('"' => '"'));

} else {

$field .= tep_parse_input_field_data($GLOBALS[$name], array('"' => '"'));

}

 

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

 

$field .= '">';

 

return $field;

}

 

////

// Hide form elements

function tep_hide_session_id() {

if (defined('SID') && 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_parse_input_field_data($name, array('"' => '"')) . '"';

 

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

 

$field .= '>';

 

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

 

for ($i=0, $n=sizeof($values); $i<$n; $i++) {

$field .= '<option value="' . tep_parse_input_field_data($values[$i]['id'], array('"' => '"')) . '"';

if ($default == $values[$i]['id']) {

$field .= ' SELECTED';

}

 

$field .= '>' . tep_parse_input_field_data($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);

}

?>

Link to comment
Share on other sites

  • Replies 313
  • Created
  • Last Reply

Top Posters In This Topic

Hi - I don't know why you posted your whole html_output script here, when just the one function was changed :huh:

 

At any rate, I don't see a problem with that page - again, the pixel_black.gif and transparent.gif, etc... are not run through this mod and thus, are not affected. (If you look at the code for that page, you'll see the image reference is just "images/pixel_black.gif" as opposed to "product_thumb.php?img=images/pixel_black.gif....etc...")

 

I don't see anything wrong with the subcategory icons or tooltip text either (which isn't a graphic)... You'll have to be a bit more specific...

 

In short, the resampling is not done unless an image is specified to be scaled and that image is greater than the dimension specified via the admin.

 

In answer to your query re: server resources, I can't say exactly. It depends on what you have running, how many visits, etc... I don't imaging it's the most processor-intensive task (to resample an image vs. resizing) though...

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

Link to comment
Share on other sites

Hi Nate!

 

I've just added your contribution yesterday to the server. Everything works great! Thank you really much for your contribution!!!

 

The only thing which could be optimized is the performance of the resizing*. The only way to achive this is to create a seperat directory for the resized images. So the system needs to resize the images "on the fly" just for one time.

 

What do you think?

 

Best regards

 

Matthias

 

 

As a workflow:

In case a image should be displayed in another resolution than the original one, the resize function should check the existence of this file within the cache directory.

 

If the resized file exists the resized image should be used. Otherwise the image should be resized and saved into the cache directory.

 

In case that the resolution of the thumbnails will be changed at the adminfrontend all files within the cache directory should be deleted.

Link to comment
Share on other sites

hmmm, I guess I am missing something =)

 

I downloaded the file and got a readplease.txt.

 

I opened it and got:

 

Thanks for a great contribution Nate!....

 

Please see the forum Q&A here...(instead of posting on this page) ;)

 

http://www.oscommerce.com/forums/index.php?act=ST&f=7&t=101007

 

Thanks Nate!

 

Um, where is the the code change listed? Confused....

 

thansk!

 

T

Link to comment
Share on other sites

The only thing which could be optimized is the performance of the resizing*. The only way to achive this is to create a seperat directory for the resized images. So the system needs to resize the images "on the fly" just for one time. What do you think?

Yes, there is already a mod for this in the contributions somewhere. This one is strictly for on the fly thumbnailing. Might be easier to change that existing mod to use the GD library (if it doesn't already)

hmmm, I guess I am missing something =)  I downloaded the file and got a readplease.txt.

Yes, you are. Different files are attached to each of the posts in the contribution. The one in question was by a user using the contribs as a message board. You want the original post at the bottom and optionally apply the "resampling" changes as described in the later contribution.

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

Link to comment
Share on other sites

Thanks Nate!

 

Sorry for posting the "whole" file.....I didn't know what was causing the error on the page..hence the whole file.

 

Looking at the code...is there something that I pasted in the wrong place? (Newbie)

 

Because, looking at this product listing page for example:

http://www.shopabundle.com/default.php/cPath/37_64

 

The pixel black only goes so far....and the tooltip for the subcategory names don't show....whereas before the contribution instruction/code....they were normal.

 

I know it's not the contrib....any idea what it can be?

 

Thanks Nate........

Link to comment
Share on other sites

No idea.. The tooltip type (you mean the ALT image text, right?) shows on my installations (MS 2.2) and the black bar is not on a default installation, so I'd probably check whatever mods you applied to the templates in both cases...

 

I didn't look at your code, but it only involves replacing the tep_image function. The other functions are not involved.

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

Link to comment
Share on other sites

Hi,

 

Thanks for creating this mod ('On the Fly' Auto Thumbnailer using GD Library). As a non-programmer this is exactly what i was looking for. I've installed your mod and the pics resize nicely. The only probem is that I get the following output at the top of each page:

 

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/sanghvi/public_html/catalog/includes/functions/html_output.php:340) in /home/sanghvi/public_html/catalog/includes/functions/sessions.php on line 67

 

any ideas or suggestions?

My Website

 

thanks in advance,

siddharth

Link to comment
Share on other sites

Please ignore my last post. The problem has been fixed. I guess the online text editor that I had used corrupted the file.

 

-siddharth

Link to comment
Share on other sites

Thanks Nate...

 

I'd appreciate it if you would take a glance at my code above....maybe I put something in the wrong place. Or if someone else could help....Thanks...

Link to comment
Share on other sites

Hi Rickharris,

 

The bug has been found and fixed with respect to the scaling of 100% width images. The new package can be downloaded on the contributions page.

 

No idea what's up with your category ALT text (is that the "tooltip" text you are referring to?), it is plainly included in the tep_image function and I also added a TITLE tag to accommodate other browsers. Enjoy!

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

Link to comment
Share on other sites

Hey,

 

Just installed the contribution and I know its exactly what I'm looking for but I'm having the problem of the resized images not displaying...get the lil' red X instead. If you actually go into the product and click for the large image, it displays correctly. I can tell the script is doing its job with respect to resizing because the image placeholders with the X are actually sized correctly, but no image is loading.

 

I do believe I have a current enough version of GD installed, but if anybody wants to look at it, go to http://www.thosegeeks.com/test.php for the phpinfo(); output.

 

Any idea why this might be happening?

 

Thanks,

 

Jeremy

Link to comment
Share on other sites

Yes, you need to upload the product_thumb.php to your osCommerce catalog directory... Check out the readme.txt file for installation instructions.

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

Link to comment
Share on other sites

Thanks Nate!........;)

 

Gettin' there!

 

The pixel black / works great now!...So does the divider pixel settings! ;)

 

Still can't figure why the alt text for the subcategory image (top-right)...shows no alt text after install. Hmmmmm? It is a gif file (category and subcategory images only...not product images). But guess what...the alt text works fine in the CATEGORY listings (gif format)...but NOT the subcategory top/right pics!???

Check this out...hover over the category pics: http://www.shopabundle.com/default.php/cPath/37

 

NOW...hover over the subcategory pic:

http://www.shopabundle.com/default.php/cPath/37_64

 

See?....only a blank alt/text bubble? Any suggestions?

Link to comment
Share on other sites

Normally, I beleive that subcategory image ALT text would be the text of whatever the page title is for the product listing (I think the default is "Let's see what we have here").

 

If that language constant for the page title (HEADING_TITLE) was set to nada, as it seems to have been, then no ALT text would be displayed... You could try altering the index.php/default.php code so that the category name is included for the tep_image ALT text, instead of HEADING_TITLE...

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

Link to comment
Share on other sites

Nate:

 

Just a note to say I got your FANTASTIC image resize contrubution to work. I finally realized that I did not have PHP compiled with GD support. 10 minutes to recompile and it now works like a charm. I thank you. www.drabel.com

 

Dennis

Link to comment
Share on other sites

Back to my problem...the product_thumb.php file IS is in the catalog directory...does it just go in the base catalog directory or does it need to go somewhere within there or what? Permissions are fine on it too...

Link to comment
Share on other sites

Do you see anything in my code on (on previous page)...that may cause that problem, Nate?

 

Thanks...! Really would like to get this working ok.....

 

Rick...............

Link to comment
Share on other sites

10 minutes to recompile and it now works like a charm. I thank you.

You're welcome ;)

 

..the product_thumb.php file IS is in the catalog directory...does it just go in the base catalog directory or does it need to go somewhere within there or what? Permissions are fine on it too...

The product thumb goes in the root catalog directory - it was not in the root directory of the site you specified. If it is there and you have GD 2 installed, I can't think of a reason why it wouldn't work.

 

Do you see anything in my code on (on previous page)...that may cause that problem, Nate?

Did you not read my prior message? - it has nothing to do with that code.

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

Link to comment
Share on other sites

Yeah, its in the catalog directory. If it helps, the cart I'm working on is at http://www.appalachianproductionsinc.com/catalog and I just reuploaded product_info.php to make sure it wasn't corruption or something like that and it's still not working. I am quite sure I had GD2 installed...our PHP configuration is at http://www.thosegeeks.com/test.php.

 

Figures it'd be my luck that if it should work it doesn't....

Link to comment
Share on other sites

I would check the config for that domain specifically, it is likely your GD is not or mis-configured somehow.... It's odd that when you go to http://www.appalachianproductionsinc.com/c...oduct_thumb.php you don't get any error messages of any kind (unless you have PHP error reporting turned *OFF*?)

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

Link to comment
Share on other sites

I do get this message in Mozilla when trying to display the image directly:

 

The image ?http://www.appalachianproductionsinc.com/catalog/product_thumb.php?img=images/68e1.jpg&w=65&h=80? cannot be displayed, because it contains errors.

 

So at least we know the script is attempting to output the php as an image... I'd check the config info for that domain specifically or try the product_thumb.php without the resampling, perhaps? (uncomment the "imagecopyresized" line and comment out the imagecopyresampled line)

 

Who's the hottie @ http://www.appalachianproductionsinc.com/c...images/68e1.jpg (hoochie MAMA!)

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

Link to comment
Share on other sites

Thanks Nate......(don't growl!) ;)

 

Yep...I did read the previous message....but sorry...being a newbie...some of it went over my head. (pixel black, and separator works fine now!)... :D

 

The problem only seems to involve the "subcategory" where the products are listed...not in the upper "main categories" that list the subcategories....the alt/text works fine there.

 

I can't figure....the alt / text also works fine when over a (product pic)....in the subcategory...but not over the top/right pic for the subcategory.

 

Anybody out there have an idea of how to fix? Thanks...appreciate the help.

 

See what I mean here: http://www.shopabundle.com/default.php/cPath/39

 

The product pics...buy now buttons, etc...all have the alt text...just NOT the top/right pic...which has a yellow popup box...but no text. Hmmm..........

 

Thanks Folks...

Link to comment
Share on other sites

Hey Nate...

 

Oh, yeah...how do you think the contribution would perform under heavy site traffic? I know you mentioned earlier about it maybe using up more server juice.

 

Would this perform better than the contributions that "break" down larger jpegs to separate, renamed, smaller thumbnails....they seem to suffer in quality at smaller sizes that way.

 

 

Thanks Buddy.....

Link to comment
Share on other sites

You know...looking at that page again....there is an alt/text bubble over the "pixel_trans.gif" also...so....maybe the alt/text bubble...even pops up over pics without text...?? Hover just below TRAVEL PRODUCTS...where the separator is located here: http://www.shopabundle.com/default.php/cPath/39 ...you'll see the bubble pops up there for the pixel, also. No big deal...but it confused me into originally thinking that there was no subtext showing in the TRAVEL PRODUCTS PIC...which it does in the main category...but not this sub.

 

Thanks Nate!...and ...thanks for a great contribution!....Saves a lot of headache! ;)

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