Jump to content

How to stop module displaying resized images


Recommended Posts

Hi all,

 

I'm using a 3rd party reviews module which displays the last 5 reviews in a block on the right column of all pages. You can see it here

 

The problem is with the way the module displays the product thumbnail. It uses this code:

<img src="{$review.product_img}" title="{$review.product_name}" style="height:45px" />

 

This actually renders the full size image but resizes it, which is bad performance wise. What I want to do is display the already resized (scaled) image produced by prestashop.

 

I've looked how other modules do this (like the blockviewed module) which uses:

<img src="{$link->getImageLink($viewedProduct->link_rewrite, $viewedProduct->cover, 'medium')}" height="{$mediumSize.height}" width="{$mediumSize.width}" alt="{$viewedProduct->legend|escape:html:'UTF-8'}" />

 

I want to do the same but use the 'small' image. I've played around with this for a while but can't get it to work. The module developers are apparently too busy with 1.5 to help with any modification..

 

Does anyone know how to do this?

 

Cheers

Link to comment
Share on other sites

Hi all,

 

I'm using a 3rd party reviews module which displays the last 5 reviews in a block on the right column of all pages. You can see it here

 

The problem is with the way the module displays the product thumbnail. It uses this code:

<img src="{$review.product_img}" title="{$review.product_name}" style="height:45px" />

 

This actually renders the full size image but resizes it, which is bad performance wise. What I want to do is display the already resized (scaled) image produced by prestashop.

 

I've looked how other modules do this (like the blockviewed module) which uses:

<img src="{$link->getImageLink($viewedProduct->link_rewrite, $viewedProduct->cover, 'medium')}" height="{$mediumSize.height}" width="{$mediumSize.width}" alt="{$viewedProduct->legend|escape:html:'UTF-8'}" />

 

I want to do the same but use the 'small' image. I've played around with this for a while but can't get it to work. The module developers are apparently too busy with 1.5 to help with any modification..

 

Does anyone know how to do this?

 

Cheers

 

Find the line you mentioned above in the module's tpl file:

 

<img src="{$review.product_img}" title="{$review.product_name}" style="height:45px" />

 

Remove style="height:45px" from that line so it will be like below:

<img src="{$review.product_img}" title="{$review.product_name}" />

 

I can't tell you where the exact location of the tpl file because of lack of information.

But hope you manage to find it.

Link to comment
Share on other sites

Hi yewster, thanks for trying, but that just displays the full sized image. I need to display the the 'small' copy of the image.

 

Ok, now i have a better understanding of what you need.

 

In order to get the same effect like blockviewed module. Open "blockviewed.php" in modules/blockviewed.

You will find the lines of code below:

 

 

$smarty->assign(array(

'productsViewedObj' => $productsViewedObj,

'mediumSize' => Image::getSize('medium')));

 

return $this->display(__FILE__, 'blockviewed.tpl');

 

What you need is to change 'mediumSize' => Image::getSize('medium')));

to 'mediumSize' => Image::getSize('small')));

to get the small image.

 

In your 3rd party module folder. Open the module php's file. Usually it is the same name

as the module folder and end with .php extension.

 

Find the line of code containing ".tpl"

Something like

 

 

$smarty->assign(array(

'productsViewedObj' => $productsViewedObj,

'mediumSize' => Image::getSize('medium')));

 

return $this->display(__FILE__, 'blockviewed.tpl');

 

or

 

$smarty->assign(array(

'special' => $special,

'priceWithoutReduction_tax_excl' => Tools::ps_round($special['price_without_reduction'], 2),

'mediumSize' => Image::getSize('medium')

));

 

return $this->display(__FILE__, 'blockspecials.tpl');

 

You won't find 'mediumSize' => Image::getSize('medium')

in it because your module do not have that line of code.

 

So just insert 'mediumSize' => Image::getSize('small') into $smarty->assign(array(

 

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

 

You can then use code like below in your tpl file to adjust the image size.

 

<img src="{$review.product_img}" title="{$review.product_name}" height="{$mediumSize.height}" width="{$mediumSize.width}" />

 

"$mediumSize" is just a variable name and example, you should rename it to "$smallSize" in both the php & tpl files.

Edited by yewster (see edit history)
Link to comment
Share on other sites

Hi yewster,

 

I made the changes you suggested but the problem is not quite solved.

 

The images are now the correct 'small' size (45px x 45px), but the image url being called is still the full size, so they are still being resized.

 

For example, the following url is currently being called by the module:

 

http://www.dermalsen...212/186-212.jpg (3696 x 5568)

 

but what I want is:

 

http://www.dermalsen...eye-complex.jpg (45x45)

 

I think I need to use something like this in the .tpl (as it does in the viewed module):

 

<img src="{$link->getImageLink($viewedProduct->link_rewrite, $viewedProduct->cover, 'medium')}"

 

I've tried replacing $viewedProduct with $review.product_img and medium to small but whatever I try just breaks the image.

 

Thanks for all your help so far.

Edited by pel024 (see edit history)
Link to comment
Share on other sites

Hi yewster,

 

I made the changes you suggested but the problem is not quite solved.

 

The images are now the correct 'small' size (45px x 45px), but the image url being called is still the full size, so they are still being resized.

 

For example, the following url is currently being called by the module:

 

http://www.dermalsen...212/186-212.jpg (3696 x 5568)

 

but what I want is:

 

http://www.dermalsen...eye-complex.jpg (45x45)

 

I think I need to use something like this in the .tpl (as it does in the viewed module):

 

<img src="{$link->getImageLink($viewedProduct->link_rewrite, $viewedProduct->cover, 'medium')}"

 

I've tried replacing $viewedProduct with $review.product_img and medium to small but whatever I try just breaks the image.

 

Thanks for all your help so far.

 

 

Open the module's .tpl file and modify the <img> line from

 

<img
src
=
"{$review.product_img}"
title
=
"{$review.product_name}"
style
=
"
height
:
45px
"
/>

To

 

{assign var="imgoriurl" value=$review.product_img}

{assign var="imgnewurl" value={$imgoriurl|regex_replace:"@^(?:http://)?([^/]+)@i":""[spam-filter]

<img src="{$imgoriurl|regex_replace:"/\/([^\/]+)\/[^\/]+$/":""}{$imgnewurl|regex_replace:"/\/([0-9]+[0-9]+-)?[0-9]+\.jpg$/":"-small/anything.jpg"}" title="{$review.product_name}"/>

 

We use regular expression. Let "anything.jpg" be "anything.jpg" as it will still display the image because of url rewriting.

I tested it on your server. You will have image with the link: http://www.dermalsen...ll/anything.jpg

which is the small image.

 

This is just a quick hack to make it happen. Try it. Hope it works!

Edited by yewster (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...