1

I know image helper class in catalog module serves good features for image related options like aspectratio, resize, frame etc.. .

My Question is i have images like customer profile image and store image and category images. So, I have to resize these images in various places and to keep its aspectratio for better image quality.

How can i use these functionalities(catalog/image helper class methods) for various images used in magento?

EDIT

I would like to store these resized images to cache. how can i store this image into cache like product images stored temporarily.

3

I've worked on a module for that a while ago. You can get it on Github. It extends the Mage_Catalog_Model_Product_Image class and uses it's functionalities to edit images.

It's probably what you are looking for.

  • But this module creates images into media/cache. I would like to remove this images when cache is removed.or i wanna make this 'media/cache' directory to magento cache, so it removed when cache removed.How can i do this? – Manikandan Arunachalam Dec 17 '14 at 9:19
  • In the model file (github.com/sandermangel/rkimages/blob/master/app/code/community/…) there are several references to the cache directory (line 67, 105,..). You could change those. The cache images will in this case be removed when you flush the image cache – Sander Mangel Dec 17 '14 at 10:01
  • But clearCache() not called anywhere in that module and there is no observer too.Then how these directory will be deleted. – Manikandan Arunachalam Dec 17 '14 at 10:05
  • When clearCache() is called?.. – Manikandan Arunachalam Dec 17 '14 at 10:15
  • clearCache should be called when the image cache is flushed. – Sander Mangel Dec 17 '14 at 11:12
3

You can do that by using "Varien_Image" Class.

// actual path of image - you can change it to any physical image path
$imageUrl = Mage::getBaseDir('media').DS."custom_image_path".DS.$obj->getImage();

// path of the resized image to be saved
// here, the resized image is saved in media/resized folder
$imageResized = Mage::getBaseDir('media').DS."custom_image_path".DS."resized".DS.$obj->getImage();

// resize image only if the image file exists and the resized image file doesn't exist
// the image is resized proportionally with the width/height 72px
if (!file_exists($imageResized) && file_exists($_imageUrl)) :
    $imageObj = new Varien_Image($_imageUrl);
    $imageObj->constrainOnly(TRUE);
    $imageObj->keepAspectRatio(TRUE);
    $imageObj->keepFrame(FALSE);
    $imageObj->resize(72, 72);
    $imageObj->save($imageResized);
endif;

You can use the resized image now as:

<img src="<?php echo Mage::getBaseUrl('media')."custom_image_path/resized/".$obj->getImage() ?>" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.