How to Change Default/Cached Thumbnail Size

product-images

I keep searching for it, but all I get are answers about changing the size on the store page and different views. What I want is to alter the size of cached thumbnail size that I get with

$product->getThumbnailUrl();

when I upload the new product and Magento creates the small image and thumbnail, not when I retrieve it.

Best Answer

By default magento not generate small_image & thumbnail on product save/create.

It will create the small_image & thumbnail image only when you try to retrieve it.

If You want to change the resize the thumbnail image just pass the parameter with $width & $height in the getThumbnailUrl function.

Refer this Mage_Catalog_Model_Product::getThumbnailUrl()

Now anwser for your question :

To create the thumbail/small image on product creation/save. We can use event observer catalog_product_save_after

<adminhtml>
    <events>
        <catalog_product_save_after>
            <observers>
                <admin_product_image_resize>
                    <class>Namespace_Module_Model_Observer</class>
                    <method>imageResize</method>
                    <type>singleton</type>
                </admin_product_image_resize>
            </observers>
        </catalog_product_save_after>
    </events>
</adminhtml>

And in Observer.php we can force the system to create the thumbnail and small image

public function imageResize($observer)
{
    $product = $observer->getEvent()->getProduct();
    try{
        if($product->getSmallImage()){
            (string)Mage::helper('catalog/image')->init($product, 'small_image')->resize(150, 150);
        }
        if($product->getThumbnail()){
            (string)Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(80, 80);
        }
    }
    catch(Exception $e){
        Mage::log($e->getMessage(), null, 'admin-image-resize.log');
    }
    return $this;
}

Refer this Link for event observer

Related Topic