Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e9f7881
Showing
17 changed files
with
863 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"pluginName":"Imager Pretransform","pluginDescription":"Pretransform any Assets on save, with Imager","pluginVersion":"2.0.0","pluginAuthorName":"Superbig","pluginVendorName":"superbig","pluginAuthorUrl":"https://superbig.co","pluginAuthorGithub":"superbigco","codeComments":"","pluginComponents":["consolecommands","controllers","models","services","settings","tasks"],"consolecommandName":"","controllerName":"","cpsectionName":"","elementName":"","fieldName":"","modelName":"TransformModel","purchasableName":"","recordName":"","serviceName":"","taskName":"","utilityName":"","widgetName":"","apiVersion":"api_version_3_0"} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# CRAFT ENVIRONMENT | ||
.env.php | ||
.env.sh | ||
.env | ||
|
||
# COMPOSER | ||
/vendor | ||
|
||
# BUILD FILES | ||
/bower_components/* | ||
/node_modules/* | ||
/build/* | ||
/yarn-error.log | ||
|
||
# MISC FILES | ||
.cache | ||
.DS_Store | ||
.idea | ||
.project | ||
.settings | ||
*.esproj | ||
*.sublime-workspace | ||
*.sublime-project | ||
*.tmproj | ||
*.tmproject | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
config.codekit3 | ||
prepros-6.config |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Imager Pretransform Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## 2.0.0 - 2018-10-22 | ||
### Added | ||
- Initial release |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2018 Superbig | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Imager Pretransform plugin for Craft CMS 3.x | ||
|
||
Pretransform any Assets on save, with Imager | ||
|
||
![Screenshot](resources/icon.png) | ||
|
||
## Requirements | ||
|
||
This plugin requires Craft CMS 3.0.0-beta.23 or later. | ||
|
||
## Installation | ||
|
||
To install the plugin, follow these instructions. | ||
|
||
1. Open your terminal and go to your Craft project: | ||
|
||
cd /path/to/project | ||
|
||
2. Then tell Composer to load the plugin: | ||
|
||
composer require superbig/craft-imagerpretransform | ||
|
||
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Imager Pretransform. | ||
|
||
## Imager Pretransform Overview | ||
|
||
If you have suffered from memory or execution time issues when creating many transforms on demand, you should look into pre-generating transforms per image. | ||
|
||
This plugin, combined with a long cache duration time, will make sure transforms will only be generated once, and one at a time. | ||
|
||
When users upload an Asset, a task will be created, which in turn will use Imager to pre-generate the transform(s). | ||
|
||
## Configuring Imager Pretransform | ||
|
||
You can either have a set of transforms per Asset source handle: | ||
|
||
```php | ||
<?php | ||
return [ | ||
'transforms' => [ | ||
// Images source, with handle images | ||
'images' => [ | ||
[ | ||
'width' => 1400, | ||
], | ||
[ | ||
'width' => 600, | ||
'jpegQuality' => 65 | ||
], | ||
[ | ||
'width' => 380, | ||
'height' => 380, | ||
'mode' => 'crop', | ||
'position' => 'center-center', | ||
'jpegQuality' => 65 | ||
], | ||
|
||
'defaults' => [ | ||
|
||
], | ||
|
||
'configOverrides' => [ | ||
'resizeFilter' => 'catrom', | ||
'instanceReuseEnabled' => true, | ||
] | ||
], | ||
|
||
'anotherSourceHandle' => [ | ||
[ | ||
'height' => 600 | ||
] | ||
] | ||
] | ||
]; | ||
``` | ||
|
||
Or just a set of transforms that will be applied to all Assets on upload/save: | ||
|
||
```php | ||
<?php | ||
return [ | ||
'transforms' => [ | ||
[ | ||
'width' => 1400, | ||
], | ||
[ | ||
'width' => 600, | ||
'jpegQuality' => 65 | ||
], | ||
[ | ||
'width' => 380, | ||
'height' => 380, | ||
'mode' => 'crop', | ||
'position' => 'center-center', | ||
'jpegQuality' => 65 | ||
], | ||
|
||
'defaults' => [], | ||
'configOverrides' => [] | ||
] | ||
]; | ||
``` | ||
|
||
You should also set Imager's cache duration to a long time, say 1 year: | ||
|
||
In imager.php: | ||
|
||
```php | ||
'cacheDuration' => 31536000, // 1 year | ||
``` | ||
|
||
If any of your transform settings depends on a value from the specific Asset, you can pass a function instead of a string. | ||
|
||
The function will be passed the AssetFileModel. | ||
|
||
As an example, this is how you would use a Focal Point field: | ||
|
||
```php | ||
<?php | ||
return [ | ||
'transforms' => [ | ||
[ | ||
'width' => 400, | ||
'height' => 400, | ||
'mode' => 'croponly', | ||
'position' => function ($asset) { | ||
return $asset->focalPointField; | ||
}, | ||
], | ||
] | ||
]; | ||
``` | ||
|
||
## Using Imager Pretransform | ||
|
||
There is 3 ways to pretransform images: | ||
- Automatically on upload | ||
- Manually through element action | ||
- imagerpretransform console command that takes either folderId or sourceHandle as argument | ||
|
||
|
||
Brought to you by [Superbig](https://superbig.co) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "superbig/craft-imagerpretransform", | ||
"description": "Pretransform any Assets on save, with Imager", | ||
"type": "craft-plugin", | ||
"version": "2.0.0", | ||
"keywords": [ | ||
"craft", | ||
"cms", | ||
"craftcms", | ||
"craft-plugin", | ||
"imager pretransform" | ||
], | ||
"support": { | ||
"docs": "https://github.com/superbigco/craft-imagerpretransform/blob/master/README.md", | ||
"issues": "https://github.com/superbigco/craft-imagerpretransform/issues" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Superbig", | ||
"homepage": "https://superbig.co" | ||
} | ||
], | ||
"require": { | ||
"craftcms/cms": "^3.0.0-RC1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"superbig\\imagerpretransform\\": "src/" | ||
} | ||
}, | ||
"extra": { | ||
"name": "Imager Pretransform", | ||
"handle": "imager-pretransform", | ||
"hasCpSettings": false, | ||
"hasCpSection": false, | ||
"changelogUrl": "https://raw.githubusercontent.com/superbigco/craft-imagerpretransform/master/CHANGELOG.md", | ||
"class": "superbig\\imagerpretransform\\ImagerPretransform" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/** | ||
* Imager Pretransform plugin for Craft CMS 3.x | ||
* | ||
* Pretransform any Assets on save, with Imager | ||
* | ||
* @link https://superbig.co | ||
* @copyright Copyright (c) 2018 Superbig | ||
*/ | ||
|
||
namespace superbig\imagerpretransform; | ||
|
||
use craft\elements\Asset; | ||
use craft\events\ElementEvent; | ||
use craft\events\RegisterElementActionsEvent; | ||
use craft\services\Elements; | ||
use superbig\imagerpretransform\elementactions\PretransformAction; | ||
use superbig\imagerpretransform\services\ImagerPretransformService as ImagerPretransformServiceService; | ||
use superbig\imagerpretransform\models\Settings; | ||
|
||
use Craft; | ||
use craft\base\Plugin; | ||
use craft\services\Plugins; | ||
use craft\events\PluginEvent; | ||
use craft\console\Application as ConsoleApplication; | ||
use craft\web\UrlManager; | ||
use craft\events\RegisterUrlRulesEvent; | ||
|
||
use yii\base\Event; | ||
|
||
/** | ||
* Class ImagerPretransform | ||
* | ||
* @author Superbig | ||
* @package ImagerPretransform | ||
* @since 2.0.0 | ||
* | ||
* @property ImagerPretransformServiceService $imagerPretransformService | ||
*/ | ||
class ImagerPretransform extends Plugin | ||
{ | ||
// Static Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var ImagerPretransform | ||
*/ | ||
public static $plugin; | ||
|
||
// Public Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $schemaVersion = '2.0.0'; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
self::$plugin = $this; | ||
|
||
if (Craft::$app instanceof ConsoleApplication) { | ||
$this->controllerNamespace = 'superbig\imagerpretransform\console\controllers'; | ||
} | ||
|
||
$this->setComponents([ | ||
'imagerPretransformService' => "superbig\\imagerpretransform\\services\\ImagerPretransformService", | ||
]); | ||
|
||
Event::on(Elements::class, Elements::EVENT_AFTER_SAVE_ELEMENT, function(ElementEvent $event) { | ||
$element = $event->element; | ||
|
||
if (self::$plugin->imagerPretransformService->shouldTransform($element)) { | ||
self::$plugin->imagerPretransformService->onSaveAsset($element); | ||
} | ||
}); | ||
|
||
Event::on(Asset::class, Asset::EVENT_REGISTER_ACTIONS, function(RegisterElementActionsEvent $event) { | ||
$event->actions[] = Craft::$app->getElements()->createAction([ | ||
'type' => PretransformAction::class, | ||
]); | ||
}); | ||
|
||
Craft::info( | ||
Craft::t( | ||
'imager-pretransform', | ||
'{name} plugin loaded', | ||
['name' => $this->name] | ||
), | ||
__METHOD__ | ||
); | ||
} | ||
|
||
// Protected Methods | ||
// ========================================================================= | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function createSettingsModel() | ||
{ | ||
return new Settings(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
/** | ||
* Imager Pretransform plugin for Craft CMS 3.x | ||
* | ||
* Pretransform any Assets on save, with Imager | ||
* | ||
* @link https://superbig.co | ||
* @copyright Copyright (c) 2018 Superbig | ||
*/ | ||
|
||
/** | ||
* Imager Pretransform config.php | ||
* | ||
* This file exists only as a template for the Imager Pretransform settings. | ||
* It does nothing on its own. | ||
* | ||
* Don't edit this file, instead copy it to 'craft/config' as 'imager-pretransform.php' | ||
* and make your changes there to override default settings. | ||
* | ||
* Once copied to 'craft/config', this file will be multi-environment aware as | ||
* well, so you can have different settings groups for each environment, just as | ||
* you do for 'general.php' | ||
*/ | ||
|
||
return [ | ||
'transforms' => [], | ||
]; |
Oops, something went wrong.