Skip to content

Commit 30a8a47

Browse files
committed
Make template for converted images optional
1 parent 2c101d8 commit 30a8a47

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ You may also change certain options from your `config.php` globally, like this:
8686
| `'hlglum'` | integer | `null` | Like `'deflum'`, but uses an appropriate diffuse white based on peak HLG |
8787
| `'jobs'` | integer | `0` | Number of jobs to use when working (`0` = unlimited) |
8888
| `'speed'` | integer | `'auto'` | Quality/speed tradeoff when encoding (AVIF only); `0` = best quality, `10` = fastest |
89-
| `'template'` | string | `'image'` | Set file blueprint for generated images |
89+
| `'template'` | string | `null` | Set file blueprint for images generated with `toFormat()` |
9090
| `'tonemap'` | string|bool | `'auto'` | Set tonemapping (`'on'` or `'off'`, but `true` & `false` are possible, too) |
9191
| `'yuv'` | string | `'auto'` | Choose yuv output format for supported formats (`'444'`, `'422'`, `'420'` or `'yv12'`) |
9292

@@ -110,6 +110,20 @@ return [
110110
$image->toFormat('avif')->thumb(['width' => 300]);
111111
```
112112

113+
**Note:** You may also define [file templates](https://getkirby.com/docs/reference/panel/blueprints/file) on a per-format basis:
114+
115+
```php
116+
// config.php
117+
118+
return [
119+
// ..
120+
'fundevogel.colorist.template' => [
121+
'avif' => 'early-bird',
122+
'webp' => 'google-lover',
123+
],
124+
];
125+
```
126+
113127
#### Methods
114128
For now, the following methods are available:
115129

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Kirby v3 wrapper for colorist",
44
"type": "kirby-plugin",
55
"license": "MIT",
6-
"version": "1.6.1",
6+
"version": "1.6.2",
77
"keywords": ["kirby3", "image", "graphics"],
88
"homepage": "https://github.com/Fundevogel/kirby3-colorist#readme",
99
"authors": [

index.php

+19-12
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'options' => [
4343
'bin' => __DIR__ . '/bin/colorist',
4444
'sizes' => [1920, 1140, 640, 320],
45-
'template' => 'image',
45+
'template' => null,
4646
'formats' => ['webp'],
4747
],
4848
'snippets' => [
@@ -124,23 +124,30 @@
124124
$src = $this->root();
125125
$dst = Str::replace($src, $oldName, $newName);
126126

127+
$fileOptions = [
128+
'source' => $dst,
129+
'parent' => $this->parent(),
130+
'filename' => $newName,
131+
];
132+
127133
$template = option('fundevogel.colorist.template');
128134

129-
# Check if there's an array with a template for each format
130-
if (is_array($template)) {
131-
if (!isset($template[$format])) {
132-
throw new Exception('No valid file template specified for format "' . $format . '"');
135+
# Check if template should be applied
136+
if ($template !== null) {
137+
# Check if there's an array with a template for each format
138+
if (is_array($template)) {
139+
if (!array_key_exists($format, $template)) {
140+
throw new Exception('No valid file template specified for format "' . $format . '"');
141+
}
142+
143+
$template = $template[$format];
133144
}
134145

135-
$template = $template[$format];
146+
# Apply template
147+
$fileOptions['template'] = $template;
136148
}
137149

138-
$file = new File([
139-
'source' => $dst,
140-
'parent' => $this->parent(),
141-
'filename' => $newName,
142-
'template' => $template,
143-
]);
150+
$file = new File($fileOptions);
144151

145152
if ($file->exists()) {
146153
return $file;

0 commit comments

Comments
 (0)