Skip to content

Commit

Permalink
Make template for converted images optional
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS committed Oct 18, 2020
1 parent 2c101d8 commit 30a8a47
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You may also change certain options from your `config.php` globally, like this:
| `'hlglum'` | integer | `null` | Like `'deflum'`, but uses an appropriate diffuse white based on peak HLG |
| `'jobs'` | integer | `0` | Number of jobs to use when working (`0` = unlimited) |
| `'speed'` | integer | `'auto'` | Quality/speed tradeoff when encoding (AVIF only); `0` = best quality, `10` = fastest |
| `'template'` | string | `'image'` | Set file blueprint for generated images |
| `'template'` | string | `null` | Set file blueprint for images generated with `toFormat()` |
| `'tonemap'` | string|bool | `'auto'` | Set tonemapping (`'on'` or `'off'`, but `true` & `false` are possible, too) |
| `'yuv'` | string | `'auto'` | Choose yuv output format for supported formats (`'444'`, `'422'`, `'420'` or `'yv12'`) |

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

**Note:** You may also define [file templates](https://getkirby.com/docs/reference/panel/blueprints/file) on a per-format basis:

```php
// config.php

return [
// ..
'fundevogel.colorist.template' => [
'avif' => 'early-bird',
'webp' => 'google-lover',
],
];
```

#### Methods
For now, the following methods are available:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Kirby v3 wrapper for colorist",
"type": "kirby-plugin",
"license": "MIT",
"version": "1.6.1",
"version": "1.6.2",
"keywords": ["kirby3", "image", "graphics"],
"homepage": "https://github.com/Fundevogel/kirby3-colorist#readme",
"authors": [
Expand Down
31 changes: 19 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'options' => [
'bin' => __DIR__ . '/bin/colorist',
'sizes' => [1920, 1140, 640, 320],
'template' => 'image',
'template' => null,
'formats' => ['webp'],
],
'snippets' => [
Expand Down Expand Up @@ -124,23 +124,30 @@
$src = $this->root();
$dst = Str::replace($src, $oldName, $newName);

$fileOptions = [
'source' => $dst,
'parent' => $this->parent(),
'filename' => $newName,
];

$template = option('fundevogel.colorist.template');

# Check if there's an array with a template for each format
if (is_array($template)) {
if (!isset($template[$format])) {
throw new Exception('No valid file template specified for format "' . $format . '"');
# Check if template should be applied
if ($template !== null) {
# Check if there's an array with a template for each format
if (is_array($template)) {
if (!array_key_exists($format, $template)) {
throw new Exception('No valid file template specified for format "' . $format . '"');
}

$template = $template[$format];
}

$template = $template[$format];
# Apply template
$fileOptions['template'] = $template;
}

$file = new File([
'source' => $dst,
'parent' => $this->parent(),
'filename' => $newName,
'template' => $template,
]);
$file = new File($fileOptions);

if ($file->exists()) {
return $file;
Expand Down

0 comments on commit 30a8a47

Please sign in to comment.