Magento 1.9 – Resize Image Using getMediaUrl

magento-1.9order-emailproduct-images

Hi there I am adding an image to order emails. So far I have managed to get the image inserted:

<?php $_item = $this->getItem() ?>
<?php 
$_product = Mage::getModel('catalog/product')
                ->setStoreId($_item->getOrder()->getStoreId())
                ->load($_item->getProductId());
?> 
<?php $_order = $this->getItem()->getOrder() ?>
<tr>
    <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
        <img src="<?php echo Mage::getModel('catalog/product_media_config')->getMediaUrl($_product->getThumbnail()); ?>" 
 alt="<?php echo $_item->getName() ?>" />
    </td>

But this produces a large image how can I get the thumbnail image or resize it to fit? I know I can resize it using the <img> tag but I'd rather call the smaller image first then resize.

Best Answer

Try this:

<?php $_item = $this->getItem() ?>
<?php 
$_product = Mage::getModel('catalog/product')
                ->setStoreId($_item->getOrder()->getStoreId())
                ->load($_item->getProductId());
?> 
<?php $_order = $this->getItem()->getOrder() ?>
<tr>
    <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(150,150); ?>" 
 alt="<?php echo $_item->getName() ?>" />
    </td>
 </tr>

OR

<?php $_item = $this->getItem() ?>
<?php $_product = $_item->getProduct();?> 
<?php $_order = $this->getItem()->getOrder() ?>
<tr>
    <td align="left" valign="top" style="font-size:11px; padding:3px 9px; border-bottom:1px dotted #CCCCCC;">
        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(150,150); ?>" 
 alt="<?php echo $_item->getName() ?>" />
    </td>
 </tr>
Related Topic