Product Thumbnail sizes in Magento

cropped-1ZTVJ.jpg

Since I’ve just moved all X-Cart product data over and the thumbnails were 150×150 Magento was upscaling the images and distorting them in the product listing pages.  I searched all over the admin area thinking surely this was a variable that could be set.  Well after searching to no availability, I started searching around and found that it is a hard set value in the template files themselves. For example:

/app/design/frontend/yourview/yourtemplate/template/catalog/product/list.phtml
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(150, 150); ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>

You’ll notice a call to the helper resize(width, height), that by default is set to 170×170 I believe. 

The only reason I can attribute to Magento not putting a width and height variable inside of the admin area is to allow template designers the ability to size the product thumbnails as they see fit for their designs. However, perhaps there should be a default value set in the admin for all product thumbnails and an override that can be called in the templates to change them if a template calls for a particular size that isn’t defaulted. However looking at the helper in /app/code/core/Mage/Catalog/Helper/Image.php you’ll notice if you can just call resize() without a width or height, and it appears it will determine the best dimensions to calculate. If you look at bit closer at the Model controlling the Image helper at: /app/code/core/Mage/Catalog/Model/Product/Image.php: setSize();

    /**
     * Schedule resize of the image
     * $width *or* $height can be null - in this case, lacking dimension will be calculated.
     *
     * @see Mage_Catalog_Model_Product_Image
     * @param int $width
     * @param int $height
     * @return Mage_Catalog_Helper_Image
     */
    public function resize($width, $height = null)
    {
        $this->_getModel()->setWidth($width)->setHeight($height);
        $this->_scheduleResize = true;
        return $this;
    }

:arrow: Magento – thumbnail size of “New Products” – ‘How do I’ Questions – eCommerce Software for Growth.

Possibly Related Posts:


4 Responses to Product Thumbnail sizes in Magento Add your comment

  1. Manab says:

    Good tips!

    I’ve got one easy way as well! thought i could share here!

    http://subesh.com.np/2009/11/creating-custom-images-cache-in-magento/

  2. admin says:

    Thanks for the comment and link.

  3. Paulius says:

    Yes I agree this can be improved on magento. Right now by default it scales all the images and its not easy to find this option. I think a lot of people spend time wondering how to set thumbnails for each category different size or no size at all.

    I have several catgories that has different size images Vertical, Horizontal and Panoramic. And from design side I know that having magento to autoResize image will never look how you want never.

    So why not to make option for catgories to set thumbnail size option. It can be set to default to something that maybe 50% of people would be happy.

  4. Luc says:

    Looking a long time where to set image dimensions. Now I found it, I have to agree that it is very logic to put this in the template. Thanks for the info….

Leave a Reply