Simple variable plugin to declare image transforms in your config and access these within templates
This plugin requires Craft CMS 3.0.0-beta.23 or later.
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require ournameismud/autobots
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Autobots.
This provides a variable object for image transforms that can be saved in your config folder.
Your image transforms are saved in your project config folder with the name autobots.php
with arrays for your image transforms, eg:
<?php
return [
'transforms' => [
'thumbCrop' => [
'mode'=>'crop',
'width'=>'280',
'height'=>'280',
'position'=>'center-center',
],
'heroCrop' => [
'mode'=>'crop',
'width'=>'1489',
'height'=>'650',
'position'=>'center-center',
]
]
];
Your image transforms can be easily accessed in your templates, eg:
{% set transforms = craft.autobots.transforms %}
and then {{ transforms.thumbCrop }}
to access.
- Pass and retrieve specific transform into variable, eg
{% set heroCrop = craft.autobots.transforms('heroCrop') %}
Brought to you by @cole007 Autobot by rayhan maulana rikzan from the Noun Project