Installation #
To install Imager Pretransform, follow these steps:
- Download & unzip the file and place the
imagerpretransform
directory into yourcraft/plugins
directory - Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
imagerpretransform
for Craft to see it.
Imager Pretransform works on Craft 2.6.x.
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
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
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:
'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
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
Frequently asked questions
- Can I target a specific Asset field?
This is not possible yet, but i'm considering it.
Releases
- Improved: Will now skip SVGs
- Improved: Non-image Assets will now be skipped.
- Added: Added element action to pretransform images manually from Assets
- Added: Added console command that takes either folderId or sourceHandle as argument
- Improved: It's now possible to pass a function to any transform setting, so you do dynamic transform settings based on the Asset fields.
- Added: Initial release
Currently available for Craft consulting and custom plugin development
Contact me