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.

2 Answers 2

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.

6
  • 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? Dec 17, 2014 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 Dec 17, 2014 at 10:01
  • But clearCache() not called anywhere in that module and there is no observer too.Then how these directory will be deleted. Dec 17, 2014 at 10:05
  • When clearCache() is called?.. Dec 17, 2014 at 10:15
  • clearCache should be called when the image cache is flushed. Dec 17, 2014 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() ?>" />
1
  • useful but want to use helper catalog/image class features. Dec 17, 2014 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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