Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

'On the Fly' Auto Thumbnailer using GD Library


Guest

Recommended Posts

  • Replies 313
  • Created
  • Last Reply

Top Posters In This Topic

I have installed this contribution but i can't use my old code. The code is for displaying a default image when the specific product image is not available.

 

The code is orginaly in tep_image function

 

if (!($image_info = @getimagesize($src))) {

$nosrc = DIR_WS_IMAGES.'notavailable.gif';

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

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

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

}

}

 

$image = '<IMG SRC="'.$nosrc.'" title="'.$src.'"';

 

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

$image .= ' width="' . tep_parse_input_field_data($width, array('"' => '"')) . '" height="' . tep_parse_input_field_data($height, array('"' => '"')) . '"';

}

 

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

 

$image .= '>';

return $image;

}

 

Where should I put the code in?

Link to comment
Share on other sites

This should work but I haven't tested it so no guarantees ;) Hope it helps!

 

Don

 

// "On the Fly" Auto Thumbnailer using GD Library originally Nate Welch (v1.5) Updated by various contributors (v1.7.1)
// 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 . '"';

// Dont 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 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) {

$width = intval($height / $ratio);

} elseif ($width && !$height) {

$height = intval($width * $ratio);

} elseif (!$width && !$height) {

$width = $image_size[0];
$height = $image_size[1];
}


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


  } elseif (IMAGE_REQUIRED == 'false') {
    return '';
  } else {
     //the image did not exist and it is required so return a default image     
     $image = '<img src="'.DIR_WS_IMAGES.'notavailable.gif" ';
  }
}

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

Link to comment
Share on other sites

Must be something to do with the arguments you're sending to the function, add:

 

print $src;

 

immediately after:

 

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

 

 

In order to see what you're passing in, then check if that image exists and that the path is correct. You'll probably find that the path is wrong.

 

Good luck,

 

Don

Link to comment
Share on other sites

Hey Nate,

 

Don't know if you are monitoring anymore. . .looks like it has been a while since you posted.

 

I just wanted to say thank you!

 

I installed your Contrib today and it works flawlessly (well -- all but the admin which is no big deal), on the first try.

 

Good job. :D

Link to comment
Share on other sites

Thanks David, I do but I only get the post notifications sporatically, it seems, and many of the questions have to do with the unauthorized "hacks" others posted on the contribution page, so I can't readily answer them and no longer know if the poster is using the original version or not...

 

Thanks for the note, though. I like being able to have small, intermediate and large images all with only uploading one image file. It's not so much work for the server to resize "on the fly" especially when most oSc site don't get *that* much traffic.

 

As for t/n's in the admin, I think someone had a hack/fix for that maybe in this thread or another or posted on the contrib page itself. I'd integrate it myself in another release, but others would just come by and muck it up ;)

 

Thanks again!

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

Link to comment
Share on other sites

I find a quite interesting thing.

 

when I change the "DIR_WS_IMAGES" to "images\" most of image displayed. But those images with width and height specified cannot be displayed. In addition, the thumb is not correctly displayed too.

 

When I change "DIR_WS_IMAGES" to "..\images\", all the images change to notavailable.gif

 

What's wrong with the code?

Link to comment
Share on other sites

This should work but I haven't tested it so no guarantees  ;) Hope it helps!

 

Don

 

// "On the Fly" Auto Thumbnailer using GD Library originally Nate Welch (v1.5) Updated by various contributors (v1.7.1)
// 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 . '"';

// Dont 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 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) {

$width = intval($height / $ratio);

} elseif ($width && !$height) {

$height = intval($width * $ratio);

} elseif (!$width && !$height) {

$width = $image_size[0];
$height = $image_size[1];
}
 $image = '<img src="product_thumb.php?img='.$src.'&w='.tep_output_string($width).'&h='.tep_output_string($height).'"';
  } elseif (IMAGE_REQUIRED == 'false') {
    return '';
  } else {
     //the image did not exist and it is required so return a default image     
     $image = '<img src="'.DIR_WS_IMAGES.'notavailable.gif" ';
  }
}

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

Hello Don

 

After numerous attempt using both the contribution and the modified file that you provided above, nothing still works. I was about to give up with thumbnail contribution. I gave the contribution a last try and found out where the problem is. My logo in the header.php was the problem. I added an extra hspace="10px" value to it and this was the culprit. I removed it and now everything is okay. Now I have crispy thumbnails for all the product photo.

 

There are still some pics which I noticed are not showing though. They are not very important but I wish I could fix it. It is the line in the shopping cart above the sub-total amount that is missing now. Also, the progress line with the small circle (Delivery Information, Payment Information, Confirmation and Finished!) when the customer starts confirming the order is also missing. Just small details.

 

I'll post the pics of the shopping cart here next time. Anyway, thanks for all the help.

 

Thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hi there Nate and everybody who helped making this contrib such a good thing!

:D

****

 

for all those of you who had problems with this contrib..

 

please, be sure you replace the whole function in html_output.php

 

so,

****************

 

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

}

 

****************

 

should replaced with the code fomr the readme file from the contrib-package..

 

so,

******************

 

// "On the Fly" Auto Thumbnailer using GD Library originally Nate Welch (v1.5) Updated by various contributors (v1.7.1)

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

}

 

*****************

 

This was the problem i was having for a second, that i only replaced the code

********

 

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

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

return false;

}

 

**************

 

SO please check!!

 

Best regards

Kasper

Link to comment
Share on other sites

I'm hoping someone with far more skill than I have can point me in the right direction. I thought I had the contrib working but I spoke too soon.

 

Here is the scenario. . .

 

To get the contrib to work, (which it does quite well), I have the following in my configure.php:

 

define('HTTP_SERVER', 'http://www.mystore.com');

define('HTTPS_SERVER', 'https://www.mystore.com');

define('ENABLE_SSL', true); // secure webserver for checkout procedure?

define('HTTP_COOKIE_DOMAIN', 'http://www.mystoret.com');

define('HTTPS_COOKIE_DOMAIN', 'https://www.mystoret.com');

define('HTTP_COOKIE_PATH', '/');

define('HTTPS_COOKIE_PATH', '/');

define('DIR_WS_HTTP_CATALOG', '/products/');

define('DIR_WS_HTTPS_CATALOG', '/products/');

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

define('DIR_WS_ICONS', 'icons/');

define('DIR_WS_INCLUDES', 'includes/');

define('DIR_WS_BOXES', DIR_WS_INCLUDES . 'boxes/');

 

etc.

 

I am also using an .htaccess file to redirect incoming traffic from www.mystore.com to www.mystore.com/products ("products" as the name of my catalog directory)(And if anyone has a better way without using a splash page...I'm all ears. :) )

 

With the above configuration, after browsing about three pages I get a 404 forbidden error, and can't go back, forward etc. until I clear the cache and cookies, and then I sometimes get broken images.

 

With the following in my configure.php the store work flawlessly, but the contrib will not work. I just get the small images from the regular install (no thumbs_image.xxx).

 

define('HTTP_SERVER', 'http://www.mystore.com');

define('HTTPS_SERVER', 'https://www.mystore.com');

define('ENABLE_SSL', true); // secure webserver for checkout procedure?

define('HTTP_COOKIE_DOMAIN', 'http://www.mystore.com');

define('HTTPS_COOKIE_DOMAIN', 'https://www.mystoret.com');

define('HTTP_COOKIE_PATH', '/');

define('HTTPS_COOKIE_PATH', '/');

define('DIR_WS_HTTP_CATALOG', '/products/');

define('DIR_WS_HTTPS_CATALOG', '/products/');

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

define('DIR_WS_ICONS', '/products/icons/');

define('DIR_WS_INCLUDES', 'includes/');

define('DIR_WS_BOXES', DIR_WS_INCLUDES . 'boxes/');

 

I know it has to do with the session Ids / cookies, but don't have a clue as to how to fix it.

 

Any help would be *GREATLY* appreciated.

Link to comment
Share on other sites

Hi - it doesn't sound like it's related to the thumbnailer per se... I might check around the forums for 403 forbidden error (I think that's what you meant to say) ;)

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

Link to comment
Share on other sites

Hi - it doesn't sound like it's related to the thumbnailer per se... I might check around the forums for 403 forbidden error (I think that's what you meant to say) ;)

 

 

Greetings Nate,

 

Yep, that's what I meant to say. :blink: It was 3 in the morning and I was toast.

 

Still having the problem, but at least I've excluded the .htaccess redirect as the problem. I can recreate it with, or without, the .htaccess in my root dir.

 

Has to be a path problem in my configure.php. With the "/products/images/" defined, it looks like it doesn't call your code at all, but the site functions. All cookies and session id's are set and hold. With "images/" defined, it calls your code, but then stops working and give me the 403.

 

Thanks again, I'll keep plugging.

Link to comment
Share on other sites

Using the echo comand, I found that that the "/product/" is getting dropped from the thumbnail images. And after a couple of page loads, or if you click on a thumbnail to get a larger image, or go to a product info page, then the 403 page is displayed.

 

But with the path defined in configure.php, (/products/images/) the code never calls the contrib.

 

Too bad, the images looked really great but I've read through the thread 4 times and I'm just flopping back and forth. The site works, but not with the thumbnails. The thumbnails work, but breaks the site.

 

It has to be something with the way the $src of the image is being set but I haven't a clue.

Link to comment
Share on other sites

The 403 error was happening because of a security module (mod_dosevasive) that I had installed on the server. Tweaked that, and the problem went away.

 

Reinstalled all orginal files, and started over with the contrib.

 

Worked this time. I must have added a comma, space or dropped something in the code first time around.

 

Anyway, works like a charm. Thumbs are being generated and displayed without problem.

Link to comment
Share on other sites

  • 1 month later...

I have tried install this contrib 3 times now with no success. I have followed the instructions word for word.

 

What is happening: all images appear broken. I get the red x where the images are suppose to be.

 

I dont know what other info i can give you at the moment. Did i just miss something easy or do you need more info to better figure out the problem.

 

Thank you

Link to comment
Share on other sites

I have tried install this contrib 3 times now with no success.  I have followed the instructions word for word.

 

What is happening: all images appear broken. I get the red x where the images are suppose to be.

 

I dont know what other info i can give you at the moment. Did i just miss something easy or do you need more info to better figure out the problem.

 

Thank you

 

 

Yes, I have this same problem after installing this contrib.

 

Please help.

Link to comment
Share on other sites

What is happening: all images appear broken. I get the red x where the images are suppose to be.

 

can you guys post the urls for the shops where the problem is? Most of the time a path is misconfigured.

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

 

 

HELLO,

 

I am a newbie and working on seeting up my site.

I read your thread and visited your site and find that your site is much what I am try to design.

Specially, on the way product catagories were displayed and the control of your log in to see price function. I am running a wholesale site and dealers will have to sign in to see dealer prices, otherwise it will only display suggest retail price.

Meanwhile I try to make those originl image setting changed to be able to take and display image size like 360dpi x 360dpi at 96 dpi.

 

Wuold you show me how you achieved those modifications? I can follow your instructions allright, I guess.

 

Thanks you in advance.

 

Spencer

Link to comment
Share on other sites

  • 4 weeks later...

I am having a heck of a time installing this mod. I know the servers running gd 2.0.28 and i followed the directions to a tee more than once. Here's what i get after install on the homepage:

 

Fatal error: Call to undefined function: tep_href_link() in /var/www/html/includes/application_top.php on line 467

 

Just the error on a white page and nothin else.

 

I hunted down the file and line:

 

$breadcrumb->add(HEADER_TITLE_CATALOG, tep_href_link(FILENAME_DEFAULT));

 

Please help, I dug thru the threads for a couple hours about this mod and I didn't see anything pertaining to my problem.

Link to comment
Share on other sites

Fatal error: Call to undefined function: tep_href_link() in /var/www/html/includes/application_top.php on line 467

Ben double check the changes you made in the catalog\includes\functions\html_output.php when you installed the contribution

Link to comment
Share on other sites

Thanks. After looking at it a lil closer, I noticed I had two comments that looked similar the " // The HTML href link wrapper function" and "// The HTML image wrapper function" and they both had different different functions. All fixed and running now. Thanks for setting me on the right path enigma.

Edited by Aza
Link to comment
Share on other sites

  • 2 weeks later...

Hi Nate,

It's been working successfully for a long time, but today because of the server problem provider stoped GD support suddenly. Until resolving problems I have to do something. I don't wanna return back to previous version of tep_image function. So is it possible to switch standart image showing when GD support unavailable. I mean if I can add any control whether GD support is okay or not to let function decides itself creating thumbnails

Link to comment
Share on other sites

  • 3 months later...

Loving the effeciency of this contribution! However I am encountering a small technical difficulty...

 

In admin (secured by ssl) the top two image links that *should* be visible for access to oscommerce.com and administration panel disappear (no red x, no link, nothing) once I edit admin/includes/configure.php line:

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

to read as

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

... oddly if i do not alter the path, then those two image links are visible rendering the 3rd as a red x broken link and knocking out my top left "os banner" image to a red x as well.

Havin a hard time finding out how to make this jive since the image arrays seem to be pulling similarly from the admin/index.php and icon images all residing in the main catalog/image/ folder together - any suggestions?

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