dbashyal/magento_resize_category_images

Magento Resize Category Images

Fund package maintenance!
flattr.com/github/dbashyal
Ko Fi

Installs: 1 877

Dependents: 0

Suggesters: 0

Security: 0

Stars: 62

Watchers: 8

Forks: 28

Open Issues: 0

Type:magento-module

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

This package is not auto-updated.

Last update: 2024-05-03 18:14:13 UTC


README

Click here for Magento 2 version

This is a free magento extension/module to resize category images. Join the converstation at: How to resize Magento e-Commerce category images

How to use this?

/*
 * 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>

How to crop image?

You can init image helper with path to image, then you must pass width and height to crop image. After image is cropped its saved and ready to be resized using cropped image as source image to be resized. See example code below.

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

If you are working on localhost using IP, you need to add ->setRemoveHttp(false):

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

If you are cropping image, you might consider using ->setDeveloperMode(true) on your local/staging so, you can keep changing dimensions and no need to worry about clearing cache.

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();

OR, centerCrop:

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

visit: dltr.org for more Magento Tips, Tricks and Free Extensions.