Magento调整图像大小


Magento resize image

我使用以下代码按标签显示产品图片:

$productId = $this->getProduct_id(); 
$_product = Mage::getModel('catalog/product')->load($productId);

src="<?php echo $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'mylabel')->getUrl(); ?>"

如何调整图像大小?

//图像名称

$image = ";

    // actual image path
/

/$imageUrl = Mage::getBaseDir('media').DS ."测试'。DS .$image;

在您的情况下,图片网址是

$imageUrl="<?php echo $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'mylabel')->getUrl(); ?>"

    // Give resized image path to be saved
    // here, the resized image will save in media/test/resized folder

$imageResized = Mage::getBaseDir('media').DS ."测试'。DS ."调整大小"。DS .$image;

    // image will resize only if the image file exists and the resized image file doesn't exist

 if (!file_exists($imageResized) && file_exists($imageUrl))
    {
        $imageObj = new Varien_Image($imageUrl);
        $imageObj->constrainOnly(TRUE);
        $imageObj->keepAspectRatio(TRUE);
        $imageObj->keepFrame(FALSE);
        $imageObj->resize(300, null);
        $imageObj->save($imageResized);
    }

希望这对你有帮助