Jump to content

Get image width and height in smarty


Recommended Posts

Hi all,

I am working on Prestashop 1.6 and would like to get width and height of images in Smarty template product-list.tpl. Images are lazy loaded and display in masonry, so I want them to occupy the same space before and after being loaded.

 

Unfortunately, {$categorySize.width} and {$categorySize.height} in the code below don't get the specific image dimension, but always return the same value. That means the one determined in Prestashop admin panel.

<figure {if isset($categorySize)}style="padding-bottom:{$categorySize.height/$categorySize.width*100}%"{/if} class="image_box">
<img class="product_image replace-2x img-responsive not-loaded"
     data-src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'category_default')|escape:'html':'UTF-8'}"
     alt="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}"
     title="{if !empty($product.legend)}{$product.legend|escape:'html':'UTF-8'}{else}{$product.name|escape:'html':'UTF-8'}{/if}"
     {if isset($categorySize)} width="{$categorySize.width}" height="{$categorySize.height}"{/if} itemprop="image" />
</figure>

What function should I use to display the correct dimensions of an uncropped image?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...