Skip to content

Commit

Permalink
version 0.0.2
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Crawford <[email protected]>
  • Loading branch information
engram-design committed Sep 19, 2015
1 parent b29117d commit 858efa8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ The aspect ratio of images are maintained, and will always match the maximum wid

- Enable/Disable resizing images on upload.
- Set the maximum width/height (in pixels) for uploaded images. Set to 2048px by default.
- Select which Asset sources you want resizing to be performed on.


## Roadmap

- Batch processing of existing assets.
- Update assetRecord after image resize, to reflect new size.
- Restrict to specific Assets sources.
- Add image quality option.
- Provide cropping options for uploaded images.


## Changelog

#### 0.0.2

- Moved hook from `onBeforeSaveAsset` to `onSaveAsset`.
- Asset record is updated after resize, reflecting new image width/height/size.
- Added option to restrict resizing to specific Asset sources.

#### 0.0.1

- Initial release.
12 changes: 10 additions & 2 deletions imageresizer/ImageResizerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function getName()

public function getVersion()
{
return '0.0.1';
return '0.0.2';
}

public function getDeveloper()
Expand All @@ -29,8 +29,15 @@ public function getDeveloperUrl()

public function getSettingsHtml()
{
$sourceOptions = array();

foreach (craft()->assetSources->getAllSources() as $source) {
$sourceOptions[] = array('label' => $source->name, 'value' => $source->id);
}

return craft()->templates->render('imageresizer/settings', array(
'settings' => $this->getSettings(),
'sourceOptions' => $sourceOptions,
));
}

Expand All @@ -40,6 +47,7 @@ protected function defineSettings()
'enabled' => array( AttributeType::Bool, 'default' => true ),
'imageWidth' => array( AttributeType::Number, 'default' => '2048' ),
'imageHeight' => array( AttributeType::Number, 'default' => '2048' ),
'assetSources' => array( AttributeType::Mixed, 'default' => '*' ),
);
}

Expand All @@ -50,7 +58,7 @@ protected function defineSettings()

public function init()
{
craft()->on('assets.onBeforeSaveAsset', function(Event $event) {
craft()->on('assets.onSaveAsset', function(Event $event) {
if (craft()->imageResizer->getSettings()->enabled) {
$asset = $event->params['asset'];

Expand Down
25 changes: 24 additions & 1 deletion imageresizer/services/ImageResizerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public function resize($asset)
{
// Get the full path of the asset we want to resize
$path = $this->_getImagePath($asset);

// If the path is false, we're not allowed to modify images in the source - kill it!
if (!$path) {
return true;
}

$image = craft()->images->loadImage($path);

// Our maximum width/height for assets from plugin settings
Expand All @@ -38,6 +44,14 @@ public function resize($asset)
}

$image->saveAs($path);

// Then, make sure we update the asset info as stored in the database
$fileRecord = AssetFileRecord::model()->findById($asset->id);
$fileRecord->size = IOHelper::getFileSize($path);
$fileRecord->width = $image->getWidth();
$fileRecord->height = $image->getHeight();

$fileRecord->save(false);
}


Expand All @@ -51,7 +65,16 @@ private function _getImagePath($asset)

// Can only deal with local assets for now
if ($source->type != 'Local') {
return true;
return false;
}

// Should we be modifying images in this source?
$assetSources = $this->getSettings()->assetSources;

if ($assetSources != '*') {
if (!in_array($source->id, $assetSources)) {
return false;
}
}

$sourcePath = $source->settings['path'];
Expand Down
9 changes: 9 additions & 0 deletions imageresizer/templates/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,13 @@
size: 10,
}) }}

{{ forms.checkboxSelectField({
label: 'Asset Sources' | t,
instructions: 'Select which asset sources you want to allow Image Resizer work with.' | t,
id: 'assetSources',
name: 'assetSources',
values: settings.assetSources,
options: sourceOptions,
}) }}

<hr>

0 comments on commit 858efa8

Please sign in to comment.