Skip to content

Commit 3448de2

Browse files
committed
Initial commit
0 parents  commit 3448de2

File tree

6 files changed

+181
-0
lines changed

6 files changed

+181
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*~

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Magento Resize at upload</h1>
2+
<p>Magento module that automatically resizes product images at upload to save disk space.</p>
3+
<p>Prevents from filling disk quota too quickly when uploading HD images.</p>
4+
5+
<h2>Configuration</h2>
6+
<p>Use the Settings menu to define max width, max heigth and disable module.</p>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
require_once('Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php');
4+
5+
class IRCF_ResizeAtUpload_Catalog_Product_GalleryController extends Mage_Adminhtml_Catalog_Product_GalleryController{
6+
7+
public function isResizeEnabled(){
8+
return Mage::getStoreConfig('resizeatupload/settings/enable') && $this->getResizeMaxWidth()+$this->getResizeMaxWidth()>0;
9+
}
10+
11+
public function getResizeMaxWidth(){
12+
return Mage::getStoreConfig('resizeatupload/settings/maxwidth');
13+
}
14+
15+
public function getResizeMaxHeight(){
16+
return Mage::getStoreConfig('resizeatupload/settings/maxheight');
17+
}
18+
19+
public function uploadAction(){
20+
if($this->isResizeEnabled()){
21+
$imageTmpName = $_FILES['image']['tmp_name'];
22+
$imageInfo = getimagesize($imageTmpName);
23+
list ($type, $subtype) = explode('/', $imageInfo['mime']);
24+
if ($type == 'image'){
25+
$image = new Varien_Image($imageTmpName);
26+
$image->constrainOnly(false);
27+
$image->keepFrame(false);
28+
$image->keepAspectRatio(true);
29+
$image->keepTransparency(true);
30+
if (
31+
$this->getResizeMaxHeight() > 0
32+
&& (
33+
$this->getResizeMaxWidth() <= 0
34+
|| $imageInfo['0']/$imageInfo['1'] < $this->getResizeMaxWidth()/$this->getResizeMaxHeight()
35+
)
36+
){
37+
if($imageInfo['1'] > $this->getResizeMaxHeight()){
38+
$image->resize(null, $this->getResizeMaxHeight());
39+
}
40+
}else{
41+
if($imageInfo['0'] > $this->getResizeMaxWidth()){
42+
$image->resize($this->getResizeMaxWidth(), null);
43+
}
44+
}
45+
$image->save($imageTmpName);
46+
}
47+
}
48+
parent::uploadAction();
49+
}
50+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<modules>
4+
<IRCF_ResizeAtUpload>
5+
<version>0.1.0</version>
6+
</IRCF_ResizeAtUpload>
7+
</modules>
8+
<admin>
9+
<routers>
10+
<adminhtml>
11+
<args>
12+
<modules>
13+
<ircf_resizeatupload before="Mage_Adminhtml">IRCF_ResizeAtUpload</ircf_resizeatupload>
14+
</modules>
15+
</args>
16+
</adminhtml>
17+
</routers>
18+
</admin>
19+
<adminhtml>
20+
<acl>
21+
<resources>
22+
<admin>
23+
<children>
24+
<system>
25+
<children>
26+
<config>
27+
<children>
28+
<resizeatupload>
29+
<title>IRCF Resize At Upload Module Section</title>
30+
</resizeatupload>
31+
</children>
32+
</config>
33+
</children>
34+
</system>
35+
</children>
36+
</admin>
37+
</resources>
38+
</acl>
39+
</adminhtml>
40+
<default>
41+
<resizeatupload>
42+
<settings>
43+
<enable>1</enable>
44+
<maxwidth>1140</maxwidth>
45+
<maxheight>1080</maxheight>
46+
</settings>
47+
</resizeatupload>
48+
</default>
49+
</config>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<tabs>
4+
<ircf translate="label">
5+
<label>IRCF Extensions</label>
6+
<sort_order>1000000</sort_order>
7+
</ircf>
8+
</tabs>
9+
<sections>
10+
<resizeatupload translate="label">
11+
<label>Resize At Upload</label>
12+
<tab>ircf</tab>
13+
<frontend_type>text</frontend_type>
14+
<sort_order>1000</sort_order>
15+
<show_in_default>1</show_in_default>
16+
<show_in_website>1</show_in_website>
17+
<show_in_store>1</show_in_store>
18+
<groups>
19+
<settings translate="label">
20+
<label>Settings</label>
21+
<frontend_type>text</frontend_type>
22+
<sort_order>100</sort_order>
23+
<show_in_default>1</show_in_default>
24+
<show_in_website>1</show_in_website>
25+
<show_in_store>1</show_in_store>
26+
<expanded>1</expanded>
27+
<fields>
28+
<enable translate="label comment">
29+
<label>Enable</label>
30+
<frontend_type>select</frontend_type>
31+
<source_model>adminhtml/system_config_source_yesno</source_model>
32+
<sort_order>10</sort_order>
33+
<show_in_default>1</show_in_default>
34+
<show_in_website>1</show_in_website>
35+
<show_in_store>1</show_in_store>
36+
</enable>
37+
<maxwidth translate="label comment">
38+
<label>Max width</label>
39+
<comment>
40+
<![CDATA[Enter max width in pixels (e.g. 1440).<br>Enter 0 to resize to a max height only.]]>
41+
</comment>
42+
<validate>required-entry validate-digits</validate>
43+
<frontend_type>text</frontend_type>
44+
<sort_order>20</sort_order>
45+
<show_in_default>1</show_in_default>
46+
<show_in_website>1</show_in_website>
47+
<show_in_store>1</show_in_store>
48+
</maxwidth>
49+
<maxheight translate="label comment">
50+
<label>Max height</label>
51+
<comment>
52+
<![CDATA[Enter max height in pixels (e.g. 1080).<br>Enter 0 to resize to a max width only.]]>
53+
</comment>
54+
<validate>required-entry validate-digits</validate>
55+
<frontend_type>text</frontend_type>
56+
<sort_order>30</sort_order>
57+
<show_in_default>1</show_in_default>
58+
<show_in_website>1</show_in_website>
59+
<show_in_store>1</show_in_store>
60+
</maxheight>
61+
</fields>
62+
</settings>
63+
</groups>
64+
</resizeatupload>
65+
</sections>
66+
</config>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<modules>
4+
<IRCF_ResizeAtUpload>
5+
<active>true</active>
6+
<codePool>local</codePool>
7+
</IRCF_ResizeAtUpload>
8+
</modules>
9+
</config>

0 commit comments

Comments
 (0)