Jump to content



Latest News: (loading..)

* * * * * 1 votes

'On The Fly' Auto Thumbnailer using GD Library 2.1


  • Please log in to reply
551 replies to this topic

#41   Fredrik.r

Fredrik.r
  • Members
  • 532 posts
  • Real Name:Fredrik
  • Gender:Male
  • Location:Stockholm, Sweden

Posted 05 October 2005 - 04:39 PM

View Postenigma1, on Oct 5 2005, 04:03 PM, said:

why the image path will be a problem? When the code flow reaches the tep_image function the path is determined. The path is totally different issue from the thumbnailer has to do with configuration settings (Unless you have a version that hardcodes the path). But its strange why the images are distorted. The images are jpg right? and you have a product_thumb.php file in the catalog\admin\ directory?

Yes thats right.

But if I use ../images/ in configure.php osC tries to find my pictures in domain.se/images when the shop is actually at domain.se/devstore/images.

#42   Fredrik.r

Fredrik.r
  • Members
  • 532 posts
  • Real Name:Fredrik
  • Gender:Male
  • Location:Stockholm, Sweden

Posted 05 October 2005 - 05:09 PM

// Example //

CODE IN PHP-FILES

In admin/categories.php;
tep_info_image($pInfo->products_image, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT)

In x-sell-php;
echo ((is_file('../images/'.$products['products_image'])) ? tep_image('../images/'.$products['products_image'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) : '<br>'.TEXT_NO_IMAGE.'<br>');

----------

VIEWING SOURCE CODE

In admin/categories.php (using the biggest image);
<img src="/devstore/images/CIMG0982.jpg" width="100" height="100"

In X-Sell (using the biggest image);
<img src="product_thumb.php?img=../images/Seiko SNL015P1 large.jpg&w=696&h=145" width="696" height="145"


(As you can see it finds the image without having ../images/ in configure.php but it's still not working)

Edited by Fredrik.r, 05 October 2005 - 05:11 PM.


#43   enigma1

enigma1
  • Members
  • 8,206 posts
  • Real Name:Mark Samios

Posted 05 October 2005 - 10:13 PM

If your admin module is in
domain.se/devstore/admin

then the ../images/ will step up a level and enter the images dir of the catalog. But if your admin module is at
domain.se/admin

is not going to work.

The x-sell should use the DIR_WS_CATALOG_IMAGES definition instead of hard-coding directories.
Now since you have this:
<img src="product_thumb.php?img=../images/Seiko SNL015P1 large.jpg&w=696&h=145" width="696" height="145"
its obvious the gd thumbnailer didn't do anything. I think the reason is it couldn't find the image path?

#44   Fredrik.r

Fredrik.r
  • Members
  • 532 posts
  • Real Name:Fredrik
  • Gender:Male
  • Location:Stockholm, Sweden

Posted 06 October 2005 - 09:56 AM

my admin is at devstore/admin.

The images shows in admin with just /images. When changing to ../images/ the categories images (which do not use product_thumb.php for some reason!?) doesnt show and there's no difference from above in the X-Sell admin page.

Edited by Fredrik.r, 06 October 2005 - 09:57 AM.


#45   enigma1

enigma1
  • Members
  • 8,206 posts
  • Real Name:Mark Samios

Posted 06 October 2005 - 04:05 PM

Ok a couple of things:

1. In your admin\categories.php make sure you have this line (near the end of the file)
$contents[] = array('text' => '<br>' . tep_info_image($pInfo->products_image, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br>' . $pInfo->products_image);

2. In your admin\includes\functions\general.php make sure you have this function
  function tep_info_image($image, $alt, $width = '', $height = '') {
	if (tep_not_null($image) && (file_exists(DIR_FS_CATALOG_IMAGES . $image)) ) {
	  $image = tep_image(DIR_WS_CATALOG_IMAGES . $image, $alt, $width, $height);
	} else {
	  $image = TEXT_IMAGE_NONEXISTENT;
	}

	return $image;
  }

3. In your admin\includes\configure.php make sure you have these definition also
define('DIR_FS_CATALOG', 'full path here'); // absolute path required
define('DIR_FS_CATALOG_IMAGES', DIR_FS_CATALOG . 'images/');
define('DIR_WS_CATALOG_IMAGES', '../images/');

the DIR_FS defs must be set correctly or the image functions will fail (as you can see from the code they may not be able to find the image file)

#46   Giacomo79

Giacomo79
  • Members
  • 21 posts
  • Real Name:PIppo
  • Gender:Male

Posted 07 October 2005 - 11:07 AM

View Postmloeffen, on Aug 19 2005, 06:15 PM, said:

As for your problem: it should work, but only since version 2.0 an aditional thumbnail-directory is supported. If you use version 2.1.2 the completely rewritten readme shows two sites where the contribution works for, and at least one store is located within root. This readme is also easier to follow when installing than the readme.txt that was included. Why not use that one?

Use the newer contribution-version and give me a link to your site (PM me if you want) and I'll help you out.
Hi,
i'm using the 2.1.2 version but i have this problem...because of my catalog is in the root directory, the images don't show.. :(

#47   camellia

camellia
  • Members
  • 4 posts
  • Real Name:nicole

Posted 08 October 2005 - 05:41 PM

hi, i can use this contribution correctly, but just wonder is it possible that the thumbnail size can be the size i set on admin-->configuare-->image-->small image size?
my shop will look awful with some thumbnail that are short than others. coz my original images are all in different sizes.
is it possible to have the thumbnail stretch to the small image size i set at admin??

thank you

#48   enigma1

enigma1
  • Members
  • 8,206 posts
  • Real Name:Mark Samios

Posted 08 October 2005 - 06:25 PM

the thumbnailer will maintain the aspect ratio. See this post for details
http://forums.oscommerce.com/index.php?s=&...ndpost&p=708388

Should be no problem even if the images are different. You can see how it is with my shop (for example the specials page)

#49   Giacomo79

Giacomo79
  • Members
  • 21 posts
  • Real Name:PIppo
  • Gender:Male

Posted 09 October 2005 - 10:40 AM

View PostGiacomo79, on Oct 7 2005, 01:07 PM, said:

Hi,
i'm using the 2.1.2 version but i have this problem...because of my catalog is in the root directory, the images don't show.. :(
Anibody can help me?
I noticed this strange behavoiur:

The thumbs are saved correctly, but in the product_thumb.php file:
// Output the image:
if ($image[2] == 2 || ($image[2] == 1 && $gif_as_jpeg))
{
	if ($tn_server_cache)
	{
		$thumbnail = modify_tn_path($_GET['img'].'.thumb_'.$_GET['w'].'x'.$_GET['h'].'.jpg');
		imagejpeg($tmp_img,$thumbnail, 100);
		//http_headers($thumbnail);
		http_headers($_GET['img']); [b]<----- I HAVE TO ADD THIS CODE TO MAKE IT WORK[/b]
See above the new code...

Cause if a let "http_headers($thumbnail);" code, the images aren't shown... :(

Edited by Giacomo79, 09 October 2005 - 10:41 AM.


#50   xty

xty
  • Members
  • 39 posts
  • Real Name:xty

Posted 09 October 2005 - 05:18 PM

I am still unable to make this contribution works. The thumbnail is not generated (broken link image), though the URL seems to be correct (points to product_thumb.php)

- osCommerce 2.2-MS2
- My hosting company uses PHP 4.3.10 (Zend: 1.3.0) (GD: 1.3.0) -> checked by php_info()
- I have done exactly the steps in the installation doc
- product_thumb.php is in root directory
- I don't use thumbnails directory for $tn_path, use '' instead, set images directory permission to 777
- GIF generation is not allowed, therefore because of the problem all osC default icons in GIF are broken
- Some parameters in product_thumb.php like $use_resampling and $use_truecolor have been set to false
- Images size settings in Admin have been set correctly

Any help would be appreciated as my store will be launched within few days. Otherwise, I'll be back to have 2 pictures-set for each product.

PS: I tried also 'otf thumbnailer with multiple thumbnail sizes' contribution earlier, it doesn't work either. Same problem, the thumbnail is not generated.

Edited by xty, 09 October 2005 - 05:21 PM.


#51   Fredrik.r

Fredrik.r
  • Members
  • 532 posts
  • Real Name:Fredrik
  • Gender:Male
  • Location:Stockholm, Sweden

Posted 09 October 2005 - 10:06 PM

View Postenigma1, on Oct 6 2005, 04:05 PM, said:

Ok a couple of things:

1. In your admin\categories.php make sure you have this line (near the end of the file)
$contents[] = array('text' => '<br>' . tep_info_image($pInfo->products_image, $pInfo->products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '<br>' . $pInfo->products_image);

2. In your admin\includes\functions\general.php make sure you have this function
  function tep_info_image($image, $alt, $width = '', $height = '') {
	if (tep_not_null($image) && (file_exists(DIR_FS_CATALOG_IMAGES . $image)) ) {
	  $image = tep_image(DIR_WS_CATALOG_IMAGES . $image, $alt, $width, $height);
	} else {
	  $image = TEXT_IMAGE_NONEXISTENT;
	}

	return $image;
  }

3. In your admin\includes\configure.php make sure you have these definition also
define('DIR_FS_CATALOG', 'full path here'); // absolute path required
define('DIR_FS_CATALOG_IMAGES', DIR_FS_CATALOG . 'images/');
define('DIR_WS_CATALOG_IMAGES', '../images/');

the DIR_FS defs must be set correctly or the image functions will fail (as you can see from the code they may not be able to find the image file)

Thank you. I have checked the three things above and they are there. I will check all install instructions (again).. I'll get back if I can't manage to solve it.

#52   Fredrik.r

Fredrik.r
  • Members
  • 532 posts
  • Real Name:Fredrik
  • Gender:Male
  • Location:Stockholm, Sweden

Posted 09 October 2005 - 10:58 PM

Ok, I have checked all.. still no thumbnails in admin.. :(

#53   Giacomo79

Giacomo79
  • Members
  • 21 posts
  • Real Name:PIppo
  • Gender:Male

Posted 11 October 2005 - 11:03 AM

I noticed that "my" file_exists function doesn't work if in the filename there is a dot (Like "name.php.thumb.jpg")

Anybody else noticed this problem?

#54   Giacomo79

Giacomo79
  • Members
  • 21 posts
  • Real Name:PIppo
  • Gender:Male

Posted 11 October 2005 - 11:18 AM

View PostGiacomo79, on Oct 11 2005, 01:03 PM, said:

I noticed that "my" file_exists function doesn't work if in the filename there is a dot (Like "name.php.thumb.jpg")

Anybody else noticed this problem?
Errata corrige: i noticed that files created with this contribution don't come seen from "file_exists" function. If i create a file in the same directory, the file_exists function works... :(

Somebody can explain this pls?

#55   enigma1

enigma1
  • Members
  • 8,206 posts
  • Real Name:Mark Samios

Posted 11 October 2005 - 07:32 PM

Ok there is this for the image path in the catalog\admin\product_thumb.php

// If you are required to set the full path for file_exists(), set this:
// $filename = '/your/path/to/catalog/'.$filename;

What is the $filename variable set in each of the cases that doesn't work? Or its still commented out?

Edited by enigma1, 11 October 2005 - 07:32 PM.


#56   Giacomo79

Giacomo79
  • Members
  • 21 posts
  • Real Name:PIppo
  • Gender:Male

Posted 11 October 2005 - 10:02 PM

View Postenigma1, on Oct 11 2005, 09:32 PM, said:

Ok there is this for the image path in the catalog\admin\product_thumb.php

// If you are required to set the full path for file_exists(), set this:
// $filename = '/your/path/to/catalog/'.$filename;

What is the $filename variable set in each of the cases that doesn't work? Or its still commented out?
I saw it, and it doesn't work anyway... :(
I guess it's a bug of "file_exists" php function, i'm looking for it on web and this function are other problems

#57   thessrtech

thessrtech
  • Members
  • 106 posts
  • Real Name:albert

Posted 13 October 2005 - 10:00 AM

View PostGiacomo79, on Oct 11 2005, 10:02 PM, said:

I saw it, and it doesn't work anyway... :(
I guess it's a bug of "file_exists" php function, i'm looking for it on web and this function are other problems


Parse error: parse error, unexpected '}' in /home/addictiv/public_html/catalog/includes/functions/html_output.php on line 192

Why do I keep getting a parse error, does OTF work with BTS?

#58   thessrtech

thessrtech
  • Members
  • 106 posts
  • Real Name:albert

Posted 13 October 2005 - 11:47 AM

View Postthessrtech, on Oct 13 2005, 10:00 AM, said:

Parse error: parse error, unexpected '}' in /home/addictiv/public_html/catalog/includes/functions/html_output.php on line 192

Why do I keep getting a parse error, does OTF work with BTS?

Anyone? This is very annoying, it only happens when i go to includes/functions/html_output.php and change

  function tep_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
	if ( (empty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
	  return false;
	}

TO

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


#59   Hotwire

Hotwire
  • Members
  • 100 posts
  • Real Name:John Brent
  • Location:Petawawa

Posted 14 October 2005 - 04:01 PM

Im having an issue with This contrib, Acctualy I think I have V.1 installed. I will double check, but...

Iv got it installed, and I have GDlib installed and running. How ever i am not getting the thumbnails to show. I keep getting the broken image links popping up instead. Its kinda making me mad. Iv worked on this site for like over a year, spending long hours modding code, and adding in contribs. If any one can help me please do.

Im running MS2 with STS if that helps out at all.
++++++++++++++++++++
Im just a guy, Nothing more
++++++++++++++++++++

#60   sydney

sydney
  • Members
  • 20 posts
  • Real Name:Sydney

Posted 15 October 2005 - 05:43 AM

The same thing is happening to me except many of the pictures do work but some other pictures don't show up (have an X) but when I "click to enlarge", the pictures work.

Thanks in advance for any help that you can provide!

Regards,
Sydney



I wonder if it's a bitmap versus JPEG thing?

Regards,

Sydney