View Single Post
  #1  
Old 11-17-2008, 04:28 AM
 
Pop Electronics Pop Electronics is offline
 

Senior Member
  
Join Date: Oct 2006
Posts: 131
 

Default Resize thumbnails with GD

It got me frustrated: having a nice looking shop with very ugly by browser resized images. I didn't want that anymore and looked for a solution. So I found one.
It resizes thumbnails on the fly and stores them on the server, so it only needs to do this once for every image and not over and over again.

This mod will save you a lot of bandwidth when you have a lot of products and customers.

Also see the difference:

These are actual screenshot from my shop:

BEFORE MOD:

http://www.popelectronics.nl/img/before.jpg http://www.popelectronics.nl/img/before1.jpg

AFTER MOD:

http://www.popelectronics.nl/img/after.jpg http://www.popelectronics.nl/img/after1.jpg

This is how to do it:

First we'll need to download a php script by Joe Lencioni called Smart Image Resizer: http://shiftingpixel.com/2008/03/03/smart-image-resizer/

Once you unpacked the image.php file rename it to imager.php (because there already is such a file in X-Cart, we don't want to overwrite that one).
Upload the file into your X-Cart installation folder.

Next make a folder and name it: imagecache
Make sure this folder is writable (777)

Now we need to change 1 file. Make sure you have a backup.

VERSION 4.1.8-4.1.9

skin1/product_thumbnail.tpl

REPLACE:
Code:
{if $config.Appearance.show_thumbnails eq "Y"}<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} alt="{$product|escape}"{if $show_border eq "Y"} class="ProductBorder"{/if} />{/if}

WITH:
Code:
{if $config.Appearance.show_thumbnails eq "Y"}<img{if $id ne ''} id="{$id}"{/if} src="/imager.php/product_thumb.jpg?width={$image_x}&amp;image={$tmbn_url}" alt="{$product|escape}"{if $show_border eq "Y"} class="ProductBorder"{/if} />{/if}

VERSION 4.1.11

skin1/product_thumbnail.tpl

REPLACE:

Code:
{* $Id: product_thumbnail.tpl,v 1.19.2.1 2007/07/09 05:00:35 svowl Exp $ *} {if $config.Appearance.show_thumbnails eq "Y" or ($type ne "T" and $type ne "")}<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}

WITH:
Code:
{* $Id: product_thumbnail.tpl,v 1.19.2.1 2007/07/09 05:00:35 svowl Exp $ *} {if $config.Appearance.show_thumbnails eq "Y" or ($type ne "T" and $type ne "")}<img{if $id ne ''} id="{$id}"{/if} src="{if $tmbn_url}./imager.php/product_thumb.jpg?width={$image_x}&amp;image={$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}

Now run: www.[yourxcartsite].com/cleanup.php
(replace this with your own site )

That's it!

Note: this will only work if you have the images on the server (filesystem), not when you have images in the database.

Have fun with it! I hope you enjoy and if so let me know by posting a reply here.
__________________
X-Cart 4.7.7
Fashion Walk template
CDSEO pro, remember anoymous carts, checkout one and some mods I've done myself (ideal, froogle, export shipping labels)
@Linux php5.6, mysql5.6, dedicated server
iDeal Advanced v3.3.1 integration
Reply With Quote