Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

create thumbs from large image

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 08-20-2006, 06:57 AM
 
mrkenzie mrkenzie is offline
 

Senior Member
  
Join Date: May 2006
Posts: 182
 

Default create thumbs from large image

This mod has been tested in 4.1.0. It will allow you to only upload a product image and display a thumb and multiple size images from one. So you do not have to upload a product image and a product thumb image. If a thumbnail image exists, then it will use it instead of the product image.

I did this because I did not want to upload product images and then have to create a new image for thumbs for each of my products. I wanted to buy the Telefirma mod, but does not work in 4.1.x yet and I did not know when it will be ready for 4.1.x. It took me about 20 hours to create this, so I figured I should share it and let others benefit from this also.

Where you are calling product_thumbnail.tpl, you can pass these parameters:

tmbn_height - height of image to be created
tmbn_width - width of image to be created
tmbn_link (true or false) - whether or not to make the image a link to the original size of the image

All of the parameters that the mod takes is listed in the link in step 1, you would just need to modify the product_thumbnail.tpl to accept the parameter and pass it to thumb mod.

Here are the steps:

1. Goto this site: http://www.cerdmann.com/thumb/ and download function.thumb.php and copy into your smarty -> plugins directory

2. Replace contents of skin1\product_thumbnail.tpl with

Code:
{* $Id: product_thumbnail.tpl,v 1.19 2005/11/17 06:55:36 max Exp $ *} {if $config.Appearance.show_thumbnails eq "Y"}{if $tmbn_path_p ne ''}{thumb file=$tmbn_path_p type=2 html="style='margin:5px;' alt='$product'" addgreytohint="false" width="$tmbn_width" height="$tmbn_height" extrapolate="false" link="$tmbn_link"}{elseif $tmbn_path_t ne ''} {thumb file=$tmbn_path_t type=2 html="style='margin:5px;' alt='$product'" addgreytohint="false" width="$tmbn_width" height="$tmbn_height" extrapolate="false" link="$tmbn_link"}{else}[img]{if $tmbn_url}{$tmbn_url}{else}{if $full_url}{$http_location}{else}{$xcart_web_dir}{/if}/image.php?type={$type|default:[/img]{/if}{/if}

3. This step modifies the product.php page so that when you are searching, it returns the path to the product image.
In include\func\func.product.php find the following:
Code:
if ($current_area == "C") { $left_joins['product_taxes'] = array( "on" => "$sql_tbl[product_taxes].productid = $sql_tbl[products].productid" ); $fields[] = "$sql_tbl[product_taxes].taxid";

and add this after:
Code:
if ($current_area != "A") { $left_joins['images_P'] = array( "on" => "$sql_tbl[images_P].id = $sql_tbl[products].productid" ); $fields[] = "$sql_tbl[images_P].image_path as "; }

4. This modification passes the product and thumb image paths to product_thumbnail.tpl
In Skin1\customer\main\product.tpl find the following:
Code:
{include file="product_thumbnail.tpl" productid=$product.productid image_x=$product.image_x image_y=$product.image_y product=$product.product tmbn_url=$product.tmbn_url id="product_thumbnail" type="P"}

and replace with this:
Code:
{include file="product_thumbnail.tpl" productid=$product.productid image_x=$product.image_x image_y=$product.image_y product=$product.product tmbn_url=$product.tmbn_url id="product_thumbnail" type="P" tmbn_path_p=$product.image_path_P tmbn_path_t=$product.image_path_T }

5. This step passes the product and thumb paths to the product_thumbnail.tpl file if use popup images is checked (in admin side).
In skin1\modules\Detailed_Product_Images\popup_image. tpl find this:

and replace it with this:

6. This step allows the thumb image to be created for the product listing page. If you are not using the DSEFU mod, then only find and replace what is in the else statement.
In skin1\customer\main\products.tpl find this:

and replace with this:

7. In include\search.php find this:
Code:
$left_joins['product_memberships'] = array( "on" => "$sql_tbl[product_memberships].productid = $sql_tbl[products].productid" );

and after that, add:
Code:
if ($current_area != "A") { $left_joins['images_P'] = array( "on" => "$sql_tbl[images_P].id = $sql_tbl[products].productid" ); $fields[] = "$sql_tbl[images_P].image_path as p_image_path"; }

8. This step gets the product image path for the recommended products - I modified my recommended products to show the product image, not just a link. If you do not show a product image in recommended products, then just skip this step.
In recommends.php find this:
Code:
if ($config["Recommended_Products"]["select_recommends_list_randomly"] == "Y" && count($query_ids) > 0) { $query = "SELECT $sql_tbl[products].* FROM $sql_tbl[products] WHERE $sql_tbl[products].productid IN ('".join("','",$query_ids)."')"; } else { $query = "SELECT DISTINCT sp2.productid, $sql_tbl[products].* FROM $sql_tbl[stats_customers_products] as sp1, $sql_tbl[stats_customers_products] AS sp2, $sql_tbl[products_categories], $sql_tbl[products], $sql_tbl[categories] LEFT JOIN $sql_tbl[category_memberships] ON $sql_tbl[category_memberships].categoryid = $sql_tbl[products_categories].categoryid WHERE sp1.productid='$productid' AND sp1.login=sp2.login AND sp2.productid!='$productid' AND $sql_tbl[products].productid=sp2.productid AND $sql_tbl[products].forsale='Y' AND $sql_tbl[products].productid = $sql_tbl[products_categories].productid AND $sql_tbl[products_categories].main = 'Y' AND $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid AND $sql_tbl[categories].avail = 'Y' AND $sql_tbl[category_memberships].membershipid IN ('$user_account[membershipid]', 0) ".$avail_condition." ORDER BY $sql_tbl[products].product LIMIT ".$config["Recommended_Products"]["number_of_recommends"]; }

and replace with this:
Code:
if ($config["Recommended_Products"]["select_recommends_list_randomly"] == "Y" && count($query_ids) > 0) { $query = "SELECT $sql_tbl[products].*, $sql_tbl[images_P].image_path as p_image_path FROM $sql_tbl[products] LEFT JOIN $sql_tbl[images_P] on $sql_tbl[images_P].id=$sql_tbl[products].productid WHERE $sql_tbl[products].productid IN ('".join("','",$query_ids)."')"; } else { $query = "SELECT DISTINCT sp2.productid, $sql_tbl[products].*, $sql_tbl[images_P].image_path as p_image_path FROM $sql_tbl[stats_customers_products] as sp1, $sql_tbl[stats_customers_products] AS sp2, $sql_tbl[products_categories], $sql_tbl[products], $sql_tbl[categories] LEFT JOIN $sql_tbl[category_memberships] ON $sql_tbl[category_memberships].categoryid = $sql_tbl[products_categories].categoryid LEFT JOIN $sql_tbl[images_P] on $sql_tbl[images_P].id=$sql_tbl[products].productid WHERE sp1.productid='$productid' AND sp1.login=sp2.login AND sp2.productid!='$productid' AND $sql_tbl[products].productid=sp2.productid AND $sql_tbl[products].forsale='Y' AND $sql_tbl[products].productid = $sql_tbl[products_categories].productid AND $sql_tbl[products_categories].main = 'Y' AND $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid AND $sql_tbl[categories].avail = 'Y' AND $sql_tbl[category_memberships].membershipid IN ('$user_account[membershipid]', 0)".$avail_condition." ORDER BY $sql_tbl[products].product LIMIT ".$config["Recommended_Products"]["number_of_recommends"]; }

9. This step passes the product image path to the product_thumbnail.tpl file for recommended products (upsell). Again, if you do not show the product images for recommended products, then skip this. Also, I have a tabs mod installed, so it will be a different file than listed and the code might be slightly different.

Find where you are calling product_thumbnail.tpl (using an include) and replace it with this:
Code:
{include file="product_thumbnail.tpl" productid=$recommends[num].productid image_x=$recommends[num].image_x image_y=$recommends[num].image_y product=$recommends[num].product tmbn_url=$recommends[num].tmbn_url id="product_thumbnail" tmbn_path_p=$recommends[num].p_image_path tmbn_link="false" tmbn_width="100"}

You should be done.

I will try to post some screen shots later.

Let me know if you have any questions or problems.
__________________
Mike Kenzie
X Cart Gold Ver. 4.1.3
X-RMA
X-AOM
X-Product Comparison
Reply With Quote
  #2  
Old 08-21-2006, 10:47 AM
 
micromedia micromedia is offline
 

Member
  
Join Date: Feb 2005
Posts: 27
 

Default Re: create thumbs from large image

Hi,

This is great one.

I want to ask one thing. Can we use this mod with Product variants image? If it yes, will be perfect.

Thanks...
__________________
X Cart Gold Ver. 4.1.6
Reply With Quote
  #3  
Old 08-21-2006, 06:03 PM
 
mrkenzie mrkenzie is offline
 

Senior Member
  
Join Date: May 2006
Posts: 182
 

Default Re: create thumbs from large image

I have not coded it to work with product variants.
__________________
Mike Kenzie
X Cart Gold Ver. 4.1.3
X-RMA
X-AOM
X-Product Comparison
Reply With Quote
  #4  
Old 08-21-2006, 09:52 PM
 
mffowler mffowler is offline
 

X-Adept
  
Join Date: Mar 2003
Location: Melbourne, Australia
Posts: 811
 

Default Re: create thumbs from large image

Great- can't wait to try this! As for product variants, they have to be loaded as individual images anyways. They display in the cart, but use the main product variant image as there is no appointed thumbnail. I would like to see X-cart implement the ability to have thumbnails for product variant images.

I did here Telafirma mention a while back that his developing 4.1 version was going to include variant capabilities, so that may still be a reason to buy it... TF, any progress?

- Mike
__________________
4.1.9
Reply With Quote
  #5  
Old 08-23-2006, 12:27 AM
 
metinex metinex is offline
 

Advanced Member
  
Join Date: Feb 2006
Posts: 82
 

Default Re: create thumbs from large image

Step 3 causing SQL error messages and I got also this error:

Fatal error: Smarty error: [in product_thumbnail.tpl line 3]: syntax error: unrecognized tag: $type|default:["/img"]{/if (Smarty_Compiler.class.php, line 436) in /home/httpd/vhosts/sample.com/httpdocs/Smarty-2.6.12/Smarty.class.php on line 1095
__________________
Jay S

Xcart 4.1.3 & Mysql 5.0.20
Xcart 4.0.17 & Mysql 4.1
Apache 2.0 & Linux Whitebox 3
Reply With Quote
  #6  
Old 08-23-2006, 05:32 AM
 
mrkenzie mrkenzie is offline
 

Senior Member
  
Join Date: May 2006
Posts: 182
 

Default Re: create thumbs from large image

Try this:

2. Replace contents of skin1\product_thumbnail.tpl with

Code:
{* $Id: product_thumbnail.tpl,v 1.19 2005/11/17 06:55:36 max Exp $ *} {if $config.Appearance.show_thumbnails eq "Y"}{if $tmbn_path_p ne ''}{thumb file=$tmbn_path_p type=2 html="style='margin:5px;' alt='$product'" addgreytohint="false" width="$tmbn_width" height="$tmbn_height" extrapolate="false" link="$tmbn_link"}{elseif $tmbn_path_t ne ''} {thumb file=$tmbn_path_t type=2 html="style='margin:5px;' alt='$product'" addgreytohint="false" width="$tmbn_width" height="$tmbn_height" extrapolate="false" link="$tmbn_link"}{else}<img{if $id ne ''} id="{$id}"{/if} src="{if $tmbn_url}{$tmbn_url}{else}{if $full_url}{$http_location}{else}{$xcart_web_dir}{/if}/image.php?type={$type|default:"T"}&amp;id={$productid}{/if}"{if $image_x ne 0} width="{$image_x}"{/if}{if $image_y ne 0} height="{$image_y}"{/if} style="margin:5px;" alt="{$product|escape}" />{/if}{/if}

When they changed the forum over, the img tags got messed up in the forums.

Also, this was done in 4.1.0, not 4.0.17. The SQL code is probably different.
__________________
Mike Kenzie
X Cart Gold Ver. 4.1.3
X-RMA
X-AOM
X-Product Comparison
Reply With Quote
  #7  
Old 08-23-2006, 02:01 PM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default Re: create thumbs from large image

Quote:
Originally Posted by mffowler
I did here Telafirma mention a while back that his developing 4.1 version was going to include variant capabilities, so that may still be a reason to buy it... TF, any progress?

- Mike

Yes - there is progress. The new Mod will:

* Have the ability to Enable or Disable mod (just like all other built in X-Cart Modules)
* Work with Product Variant images
* Have selectable JPG image quality
* Select to use the Unsharp mask or not
* Properly preserves Alpha transparency for PNG files
* Watermark images with Company Name (as specified in General Settings)
* Select to display Variant Images as Detail Image thumbs below the main product image on the product page
* Select to display Main Product Image as first Detail Image thumb below the main product image on the product page
* and more...
Reply With Quote
  #8  
Old 08-23-2006, 03:07 PM
 
mrkenzie mrkenzie is offline
 

Senior Member
  
Join Date: May 2006
Posts: 182
 

Default Re: create thumbs from large image

When will the new mod for 4.1.x be available?
__________________
Mike Kenzie
X Cart Gold Ver. 4.1.3
X-RMA
X-AOM
X-Product Comparison
Reply With Quote
  #9  
Old 09-01-2006, 08:48 PM
 
vulcan-works vulcan-works is offline
 

Senior Member
  
Join Date: Feb 2004
Posts: 143
 

Default Re: create thumbs from large image

i get this error:

Fatal error: Smarty error: [in product_thumbnail.tpl line 2]: syntax error: unrecognized tag 'thumb' (Smarty_Compiler.class.php, line 580) in /home/vulcan/public_html/xcart/Smarty-2.6.12/Smarty.class.php on line 1095

im using 4.1.2
__________________
X-cart--4.7.12

vulcanworks.net
Reply With Quote
  #10  
Old 09-02-2006, 06:16 AM
 
mrkenzie mrkenzie is offline
 

Senior Member
  
Join Date: May 2006
Posts: 182
 

Default Re: create thumbs from large image

Did you copy function.thumb.php into your Smarty -> plugins directory?
__________________
Mike Kenzie
X Cart Gold Ver. 4.1.3
X-RMA
X-AOM
X-Product Comparison
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 04:06 PM.

   

 
X-Cart forums © 2001-2020