/**
     * Resize category images to display
     *
     * Return image url
     *
     * @return string
     */
    public function getResizedImage($imagePath, $width, $height = null, $quality = 100) {
        
        $return = '';
        $imageUrl = Mage::getBaseDir ( 'media' ) . WT . 'catalog' . WT . "category" . WT . $imagePath;
        
        if (! $imagePath || ! is_file ( $imageUrl )) {
            $return = false;
        } else {
            /**
             * Because clean Image cache function works in this folder only
             */
            $imageResized = Mage::getBaseDir ( 'media' ) . WT . 'catalog' . WT . 'product' . WT . "cache" . WT . "cat_resized" . WT . $width . $imagePath;
            if (! file_exists ( $imageResized ) && file_exists ( $imageUrl ) || file_exists ( $imageUrl ) && filemtime ( $imageUrl ) > filemtime ( $imageResized )) :
                $imageObj = new Varien_Image ( $imageUrl );
                $imageObj->constrainOnly ( true );
                $imageObj->keepAspectRatio ( false );
                $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/" . $width . $imagePath;
            } else {
                $return = $imagePath;
            }
        }
        return $return;
    
    }

 

Your Answer
Sign In
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.