首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento调整图像大小

问Magento调整图像大小
EN

Stack Overflow用户
提问于 2013-10-16 19:19:39
回答 1查看 2.3K关注 0票数 0

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

代码语言:javascript
复制
$productId = $this->getProduct_id(); 
$_product = Mage::getModel('catalog/product')->load($productId);


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

如何调整图像的大小?

EN

回答 1

Stack Overflow用户

发布于 2013-10-16 19:49:17

//镜像名称

$image = "";

代码语言:javascript
复制
    // actual image path

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

在本例中,图像url是

代码语言:javascript
复制
$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 .'test'.DS .‘调整大小’。DS .$image;

代码语言:javascript
复制
    // 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);
    }

希望这能对你有所帮助

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19402029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档