Magento : Category images from resized folder

My Study

Generally magento category images call from media/catalog/category. But some time we want resize and want call from resized folder.

So for that make static block

{{block type=”catalog/navigation” name=”catalog.categories” template=”catalog/navigation/category_listing.phtml”}} and code for category_listing.phtml is below.

 

<?php $_helper = Mage::helper(‘catalog/category’) ?>
<?php $_categories1 = $this->getCurrentChildCategories(); ?>
<?php $_collectionSize = $_categories1->count() ;?>
<?php $_columnCount = 4; ?>
<?php $i=0;  foreach($_categories1 as $categories):  ?>
<?php if ($i++%4==0): ?>
<ul>
<?php endif ?>
<?php
$categories = Mage::getModel(‘catalog/category’)->load($categories->getId());
$actualimageUrl = $categories->getImageUrl();

if(!file_exists(“.media/catalog/category/resized”)):
mkdir(“./media/catalog/category/resized”,0777);
endif;
$actualimageName = substr(strrchr($actualimageUrl,”/”),1);
$imageUrl = Mage::getBaseDir(‘media’).DS.”catalog”.DS.”category”.DS.$actualimageName;
$imageResized = Mage::getBaseDir(‘media’).DS.”catalog”.DS.”category”.DS.”resized”.DS.$actualimageName;

if (!file_exists($imageResized)&&file_exists($imageUrl)) :
$imageObj = new Varien_Image($imageUrl);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->keepFrame(FALSE);
$imageObj->resize(200, 200);
$imageObj->save($imageResized);
endif;
?>
<li>
<a href=”<?php echo $categories->getUrl(); ?>”>
<img src=”<?php echo Mage::getBaseUrl(‘media’).”catalog/category/resized/”.$actualimageName; ?>” /></a>
<a href=”<?php echo $categories->getUrl(); ?>”><h1><?php echo $categories->getname(); ?></h1></a>
</li>
<?php if ($i%4==0 || $i==$_collectionSize): ?>
</ul>
<?php endif ?>
<?php endforeach; ?>
decorateGeneric($$(‘ul.products-grid’), [‘odd’,’even’,’first’,’last’])

View original post

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s