Skip to content

Commit 6c853c8

Browse files
committed
version 0.1.3
1 parent e790e08 commit 6c853c8

13 files changed

+380
-82
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ Image Resizer works for all Asset Sources: Local, Rackspace Cloud Files, Amazon
1414
- Enable/Disable resizing images on upload. Enabled by default.
1515
- Set the maximum width/height (in pixels) for uploaded images. Set to 2048px by default.
1616
- Set the quality for resized images between 0-100. Set to 100 by default.
17-
- Select which Asset sources you want resizing to be performed on.
17+
- If resizing results in a larger image, choose to ship. Enabled by default.
18+
19+
All the above options can be modified per-asset source.
20+
21+
- Bulk resizing for asset folders.
22+
- Cropping aspect ratios.
1823

1924

2025
## Resizing
@@ -36,16 +41,20 @@ You'll be presented with a warning screen advising that the selected images will
3641

3742
Under the hood, the batch processing is run through Craft's Tasks service, which will allow you to process plenty of images at once, without timing out or running into memory issues.
3843

44+
Additionally, using the plugin settings page (Bulk Resize tab), you can bulk-resize all assets in a single folder.
45+
3946

4047
## Cropping
4148

4249
You can crop any image through the Assets Index screen, by clicking on the Actions button, and selecting Crop image. You can only crop one image at a time. There are several preset options related to the aspect ratio to control how cropping is controlled, and are selected through the Crop modal window.
4350

4451
Activating the cropping interface upon upload of new images is on the Roadmap, and will be released soon.
4552

53+
You can manage these aspect ratios through the plugin settings page, including removing/renaming existing options, or adding your own.
54+
4655
<img src="https://raw.githubusercontent.com/engram-design/ImageResizer/master/screenshots/cropping.png" width="400" />
4756

48-
Aspect ratio options are:
57+
Default aspect ratio options are:
4958

5059
- **Free:** No restrictions
5160
- **Square:** Restricted to square crop
@@ -56,8 +65,6 @@ Aspect ratio options are:
5665
## Roadmap
5766

5867
- Provide cropping options on-upload.
59-
- Allow Asset folder selection in addition to source.
60-
- Provide hook for third-party Aspect Ratio options.
6168
- Add more features for full-featured image editor.
6269

6370

changelog.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
[
2+
{
3+
"version": "0.1.3",
4+
"downloadUrl": "https://github.com/engram-design/ImageResizer/archive/0.1.3.zip",
5+
"date": "2016-06-24T14:15:00+10:00",
6+
"notes": [
7+
"[Added] You can now specify width and height sizes on-demand in the Resizing modal window.",
8+
"[Added] Resizing can be done on an entire folder through Image Resizer settings (Bulk Resize tab).",
9+
"[Added] Allow custom aspect ratios to be defined for cropping.",
10+
"[Improved] Resizing now checks if the resulting file size is larger than the original. If larger, no action is taken.",
11+
"[Improved] You can now specify per-asset source settings, with fallbacks to your global settings."
12+
]
13+
},
214
{
315
"version": "0.1.2",
416
"downloadUrl": "https://github.com/engram-design/ImageResizer/archive/0.1.2.zip",

imageresizer/ImageResizerPlugin.php

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function getName()
1414

1515
public function getVersion()
1616
{
17-
return '0.1.2';
17+
return '0.1.3';
1818
}
1919

2020
public function getSchemaVersion()
@@ -50,13 +50,17 @@ public function getReleaseFeedUrl()
5050
public function getSettingsHtml()
5151
{
5252
$sourceOptions = array();
53-
53+
$folderOptions = array();
5454
foreach (craft()->assetSources->getAllSources() as $source) {
5555
$sourceOptions[] = array('label' => $source->name, 'value' => $source->id);
5656
}
5757

58+
$assetTree = craft()->assets->getFolderTreeBySourceIds(craft()->assetSources->getAllSourceIds());
59+
craft()->imageResizer->getAssetFolders($assetTree, $folderOptions);
60+
5861
return craft()->templates->render('imageresizer/settings', array(
5962
'settings' => $this->getSettings(),
63+
'folderOptions' => $folderOptions,
6064
'sourceOptions' => $sourceOptions,
6165
));
6266
}
@@ -68,7 +72,33 @@ protected function defineSettings()
6872
'imageWidth' => array( AttributeType::Number, 'default' => '2048' ),
6973
'imageHeight' => array( AttributeType::Number, 'default' => '2048' ),
7074
'imageQuality' => array( AttributeType::Number, 'default' => '100' ),
71-
'assetSources' => array( AttributeType::Mixed, 'default' => '*' ),
75+
'assetSources' => array( AttributeType::Mixed, 'default' => '*' ), // Deprecated
76+
'assetSourceSettings' => array( AttributeType::Mixed ),
77+
'skipLarger' => array( AttributeType::Bool, 'default' => true ),
78+
79+
// Cropping
80+
'croppingRatios' => array( AttributeType::Mixed, 'default' => array(
81+
array(
82+
'name' => 'Free',
83+
'width' => 'none',
84+
'height' => 'none',
85+
),
86+
array(
87+
'name' => 'Square',
88+
'width' => 1,
89+
'height' => 1,
90+
),
91+
array(
92+
'name' => 'Constrain',
93+
'width' => 'relative',
94+
'height' => 'relative',
95+
),
96+
array(
97+
'name' => '4:3',
98+
'width' => 4,
99+
'height' => 3,
100+
),
101+
) ),
72102
);
73103
}
74104

@@ -92,6 +122,10 @@ public function init()
92122
$folder = $event->params['folder'];
93123
$filename = $event->params['filename'];
94124

125+
// User for overrides on element action
126+
$width = null;
127+
$height = null;
128+
95129
// If we've triggered this from our cropping action, don't resize too
96130
if (craft()->httpSession->get('ImageResizer_CropElementAction')) {
97131
craft()->httpSession->remove('ImageResizer_CropElementAction');
@@ -100,26 +134,28 @@ public function init()
100134

101135
// If this has been trigged from the element actions, bypass everything below
102136
if (!craft()->httpSession->get('ImageResizer_ResizeElementAction')) {
103-
// Make sure we check out config setting
104-
if (craft()->imageResizer->getSettings()->enabled) {
137+
// We can have settings globally, or per asset source. Check!
138+
$sourceEnabled = craft()->imageResizer->getSettingForAssetSource($folder->source->id, 'enabled');
105139

106-
// Should we be modifying images in this source?
107-
$assetSources = craft()->imageResizer->getSettings()->assetSources;
108-
109-
if ($assetSources != '*') {
110-
if (!in_array($folder->source->id, $assetSources)) {
111-
return true;
112-
}
113-
}
140+
// Should we be modifying images in this source?
141+
if (!$sourceEnabled) {
142+
return true;
114143
}
115144
} else {
116145
// If we are from a element action - delete this so it doesn't persist
117146
craft()->httpSession->remove('ImageResizer_ResizeElementAction');
147+
148+
// We also might ne overriding width/height
149+
$width = craft()->httpSession->get('ImageResizer_ResizeElementActionWidth');
150+
$height = craft()->httpSession->get('ImageResizer_ResizeElementActionHeight');
151+
152+
craft()->httpSession->remove('ImageResizer_ResizeElementActionWidth');
153+
craft()->httpSession->remove('ImageResizer_ResizeElementActionHeight');
118154
}
119155

120156
// Is this a manipulatable image?
121157
if (ImageHelper::isImageManipulatable(IOHelper::getExtension($filename))) {
122-
craft()->imageResizer_resize->resize($path);
158+
craft()->imageResizer_resize->resize($folder->source->id, $path, $width, $height);
123159
}
124160
});
125161
}

imageresizer/controllers/ImageResizerController.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@ public function actionResizeElementAction()
99
$this->requireAjaxRequest();
1010
$this->requireAdmin();
1111

12-
$assetIds = craft()->request->getRequiredPost('assetIds');
12+
$assetIds = craft()->request->getPost('assetIds');
13+
$imageWidth = craft()->request->getPost('imageWidth');
14+
$imageHeight = craft()->request->getPost('imageHeight');
15+
$bulkResize = craft()->request->getPost('bulkResize');
16+
$assetFolderId = craft()->request->getPost('assetFolderId');
17+
18+
if ($bulkResize) {
19+
$criteria = craft()->elements->getCriteria(ElementType::Asset);
20+
$criteria->limit = null;
21+
$criteria->folderId = $assetFolderId;
22+
$assetIds = $criteria->ids();
23+
}
1324

1425
craft()->tasks->createTask('ImageResizer', 'Resizing images', array(
1526
'assets' => $assetIds,
27+
'imageWidth' => $imageWidth,
28+
'imageHeight' => $imageHeight,
1629
));
1730

1831
craft()->end();

imageresizer/elementactions/ImageResizer_CropImageElementAction.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ public function getTriggerHtml()
1313
craft()->templates->includeJsResource('lib/jcrop/jquery.Jcrop.min.js');
1414
craft()->templates->includeCssResource('lib/jcrop/jquery.Jcrop.min.css');
1515

16+
$croppingRatios = craft()->imageResizer->getSettings()->croppingRatios;
17+
1618
craft()->templates->includeCssResource('imageresizer/css/CropElementAction.css');
1719
craft()->templates->includeJsResource('imageresizer/js/CropElementAction.js');
18-
craft()->templates->includeJs('new Craft.CropElementAction();');
20+
21+
craft()->templates->includeJs('new Craft.CropElementAction(' .
22+
''.json_encode($croppingRatios).'' .
23+
');');
1924
}
2025
}

imageresizer/resources/css/ResizeElementAction.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
position: absolute;
3838
}
3939

40+
.image-resizer-modal .footer .buttons.rightalign {
41+
float: right;
42+
}
43+
4044

4145

4246
.image-resizer-modal .task {

imageresizer/resources/css/Settings.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@
4545
margin-right: 10px;
4646
}
4747

48+
.bulk-resize-table td {
49+
padding: 5px 20px 5px 0;
50+
}
4851

imageresizer/resources/js/CropElementAction.js

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function() {
22
Craft.CropElementAction = Garnish.Base.extend({
33

4-
init: function() {
4+
init: function(croppingRatios) {
55
var cropTrigger = new Craft.ElementActionTrigger({
66
handle: 'ImageResizer_CropImage',
77
batch: false,
@@ -10,7 +10,7 @@ Craft.CropElementAction = Garnish.Base.extend({
1010
return (documents > 0) ? false : true;
1111
},
1212
activate: function($selectedItems) {
13-
new Craft.CropImageModal($selectedItems.find('.element'), $selectedItems, {});
13+
new Craft.CropImageModal($selectedItems.find('.element'), $selectedItems, { croppingRatios: croppingRatios });
1414
}
1515
});
1616
},
@@ -37,6 +37,7 @@ Craft.CropImageModal = Garnish.Modal.extend(
3737
init: function($element, $selectedItems, settings) {
3838
this.$element = $element;
3939
this.$selectedItems = $selectedItems;
40+
this.settings = settings;
4041

4142
this.desiredWidth = 400;
4243
this.desiredHeight = 280;
@@ -74,13 +75,13 @@ Craft.CropImageModal = Garnish.Modal.extend(
7475
},
7576

7677
setupAspectRatio: function() {
78+
var menuOptions = '';
79+
$.each(this.settings.croppingRatios, function(index, item) {
80+
menuOptions += '<li><a data-action="' + index + '" data-width="' + item.width + '" data-height="' + item.height + '">' + Craft.t(item.name) + '</a></li>';
81+
});
82+
7783
var $menu = $('<div class="menu">' +
78-
'<ul>' +
79-
'<li><a data-action="free">'+Craft.t('Free')+'</a></li>' +
80-
'<li><a data-action="square">'+Craft.t('Square')+'</a></li>' +
81-
'<li><a data-action="constrain">'+Craft.t('Constrain')+'</a></li>' +
82-
'<li><a data-action="4_3">'+Craft.t('4:3')+'</a></li>' +
83-
'</ul>' +
84+
'<ul>' + menuOptions + '</ul>' +
8485
'</div>').insertAfter(this.$aspectRatioSelect);
8586

8687
var MenuButton = new Garnish.MenuBtn(this.$aspectRatioSelect, {
@@ -101,29 +102,17 @@ Craft.CropImageModal = Garnish.Modal.extend(
101102
var width = $img.width();
102103
var height = $img.height();
103104

104-
if ($option.data('action') == 'free') {
105-
this.areaSelect.setOptions({ aspectRatio: null });
106-
} else if ($option.data('action') == 'square') {
107-
this.areaSelect.setOptions({ aspectRatio: 1 / 1 });
108-
109-
if (width > height) {
110-
width = height;
111-
} else {
112-
height = width;
113-
}
105+
var action = $option.data('action');
106+
var widthConstraint = $option.data('width');
107+
var heightConstraint = $option.data('height');
114108

115-
} else if ($option.data('action') == 'constrain') {
116-
this.areaSelect.setOptions({ aspectRatio: width / height });
117-
} else if ($option.data('action') == '4_3') {
109+
// Cater for special aspect ratio cases
110+
if (widthConstraint == 'none') { widthConstraint = null; }
111+
if (heightConstraint == 'none') { heightConstraint = null; }
112+
if (widthConstraint == 'relative') { widthConstraint = width; }
113+
if (heightConstraint == 'relative') { heightConstraint = height; }
118114

119-
this.areaSelect.setOptions({ aspectRatio: 4 / 3 });
120-
121-
if (width > height) {
122-
width = Math.round((height / 3) * 4);
123-
} else {
124-
height = Math.round((width / 4) * 3);
125-
}
126-
}
115+
this.areaSelect.setOptions({ aspectRatio: widthConstraint / heightConstraint });
127116
},
128117

129118
onFadeOut: function() {

0 commit comments

Comments
 (0)