Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Category Image Re-size
 
pradeep_kumar67
Sr. Member
 
Avatar
Total Posts:  160
Joined:  2010-06-24
Bangalore
 

Hi,

We don’t have any function to re-size the category image, i saw one post where it clearly mention how to do it

call this code where you need to display

$_category=Mage::getModel('catalog/category')->load($categoryId());
    
$_imgUrl $_category->getResizedImage(70,70);

and extend category model to your local system or your custom module
XML

<global>
  <
models>
    <
catalog>
        <
rewrite>   
            <
category>NameSpace_Modulename_Model_Category</category>                    
        </
rewrite>                
    </
catalog>
   </
models>
</global>

in side model folder add this file Category.php which is attached in this post

<?php

class NameSpace_Modulename_Model_Category extends Mage_Catalog_Model_Category
{
   
    
public function getResizedImage($width$height null$quality 100{

        
if (! $this->getImage ())
            return 
false;
        
        
$imageUrl Mage::getBaseDir 'media' ) . DS "catalog" DS "category" DS $this->getImage ();
        if (! 
is_file ( $imageUrl ))
            
return false;
        
        
$imageResized Mage::getBaseDir 'media' ) . DS "catalog" DS "product" DS "cache" DS "cat_resized" DS $this->getImage ();// Because clean Image cache function works in this folder only
        
if (! file_exists $imageResized ) && file_exists $imageUrl ) || file_exists($imageUrl) && filemtime($imageUrl) > filemtime($imageResized)) :
            
$imageObj = new Varien_Image $imageUrl );
            
$imageObj->constrainOnly true );
            
$imageObj->keepAspectRatio true );
            
$imageObj->keepFrame false );
            
$imageObj->quality $quality );
            
$imageObj->resize $width$height );
            
$imageObj->save $imageResized );
        endif;
        
        if(
file_exists($imageResized)){
            
return Mage::getBaseUrl 'media' ) ."/catalog/product/cache/cat_resized/" $this->getImage ();
        
}else{
            
return $this->getImageUrl();
        
}
    
    } 
    
}
File Attachments
Category.php  (File Size: 2KB - Downloads: 66)
 
Magento Community Magento Community
Magento Community
Magento Community
 
maria_atwix
Sr. Member
 
Avatar
Total Posts:  129
Joined:  2012-01-23
 

Hi, here you can find solution of this problem http://www.atwix.com/magento/how-to-resize-images/

Hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top