dbashyal/magento_resize_category_images

Magento 分类图片缩放

v0.3.1 2016-07-22 10:54 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:55:40 UTC


README

点击此处 获取 Magento 2 版本

这是一个免费的 Magento 扩展/模块,用于缩放分类图片。加入以下讨论: 如何缩放 Magento 电子商务分类图片

如何使用它?

/*
 * You can pass width and height and much more, see helper for details.
 * echo $this->helper('timage')->init($_category->getImageUrl())->resize(null, 120)
 * echo $this->helper('timage')->init($_category->getImageUrl())->resize(120, null)
 * echo $this->helper('timage')->init($_category->getImageUrl())->resize(120, 120)
 */
<div class="product-image">
	<a href="<?php echo $_category->getURL() ?>" title="<?php echo $this->htmlEscape($_category->getName()) ?>">
		<img src="<?php echo $this->helper('timage')->init($_category->getImageUrl())->resize(null, 120) ?>" alt="<?php echo $this->htmlEscape($_category->getName()) ?>"/>
	</a>
</div>

如何裁剪图片?

您可以使用图片路径初始化图片助手,然后必须传入宽度和高度来裁剪图片。裁剪后,图片将被保存并准备好使用裁剪后的图片作为要缩放的源图片。以下是一个示例代码。

<img src="<?php 
	echo $this->helper('timage')
			  ->init($_category->getImageUrl())
			  ->setWidth(230)
			  ->setHeight(200)
			  ->crop()
			  ->resize() 
	?>" alt="alt text"/>

如果您在本地主机上使用 IP,您需要添加 ->setRemoveHttp(false)

<img src="<?php 
	echo $this->helper('timage')
			  ->setRemoveHttp(false)
			  ->init($_category->getImageUrl())
			  ->setWidth(230)
			  ->setHeight(200)
			  ->crop()
			  ->resize() 
	?>" alt="alt text"/>

如果您正在裁剪图片,您可能需要在您的本地/测试环境中使用 ->setDeveloperMode(true),这样您可以不断更改尺寸,无需担心清除缓存。

Mage::helper('timage')
                ->init(Mage::getBaseUrl('media') . 'catalog/product' . $product['giftcard_image'])
                ->setWidth(780)
                ->setHeight(505)
                ->keepFilename(true)
                ->keepAspectRatio(false)
                ->setDeveloperMode(true)
                ->crop(280, 10, 10, 280)
                ->resize();

或者,使用中心裁剪

Mage::helper('timage')
            ->init(Mage::getBaseUrl('media') . 'catalog/product' . $image)
            ->setWidth(120)
            ->setHeight(25)
            //->keepFilename(true)
            //->keepAspectRatio(true)
            //->setDeveloperMode(true)
            ->centerCrop()
            ->resize();

访问:dltr.org 获取更多 Magento 技巧、技巧和免费扩展