-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagento_Image_resize_function.php
More file actions
52 lines (30 loc) · 1.14 KB
/
magento_Image_resize_function.php
File metadata and controls
52 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class Namespace_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
public function resizeImage($imageName, $width=NULL, $height=NULL, $imagePath=NULL)
{
$imagePath = str_replace('index.php/','',Mage::getBaseDir('media').'/store_photos/');
$imagePathFull = $imagePath.$imageName;
if($width == NULL && $height == NULL) {
$width = 100;
$height = 100;
}
$new_imagePath = str_replace('index.php/','',Mage::getBaseDir('media'));
$resizeDir = 'store_photos_resize';
$resizePathFull = $new_imagePath.'/'.$resizeDir.'/'.$imageName;
if (file_exists($imagePathFull) && !file_exists($resizePathFull)) {
$imageObj = new Varien_Image($imagePathFull);
$imageObj->constrainOnly(TRUE);
$imageObj->keepAspectRatio(TRUE);
$imageObj->resize($width,$height);
$imageObj->save($resizePathFull);
}
//$imagePath=str_replace(DS, "/", $imagePath);
$image_url=str_replace('index.php/','',Mage::getUrl('media')).$resizeDir.'/'.$imageName;
return $image_url;
}
}
/*
Call :
<img src="<?php echo Mage::helper('modulename')->resizeImage('imagename.jpg', 100, 100, 'path/image'); ?>" style="padding:10px;">
*/