Created
January 28, 2014 20:21
-
-
Save ryaan-anthony/8675526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class Ip_Category_Model_Image | |
| { | |
| public function getResizedImage($image, $width, $height = null, $quality = 100) | |
| { | |
| if(!$image){return false;} | |
| $imageUrl = Mage::getBaseDir('media').DS."catalog".DS."category".DS.$image; | |
| if(!is_file($imageUrl)){return false;} | |
| $imageResized = Mage::getBaseDir('media').DS."catalog".DS."category".DS."cache".DS."cat_resized".DS.$image; | |
| 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(true); | |
| $imageObj->quality($quality); | |
| $imageObj->backgroundColor(array(255, 255, 255)); | |
| $imageObj->resize($width,$height); | |
| $imageObj->save($imageResized); | |
| } | |
| if(file_exists($imageResized)){ | |
| return Mage::getBaseUrl('media')."catalog/category/cache/cat_resized/".$image; | |
| }else{ | |
| return $imageUrl; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment