-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.php
96 lines (89 loc) · 3.48 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
load([
'flokosiol\\focus' => 'src/Focus.php',
'flokosiol\\focus\\gdlib' => 'src/Focus/GdLib.php',
'flokosiol\\focus\\imagemagick' => 'src/Focus/ImageMagick.php'
], __DIR__);
// use Kirby\Cms\App;
use Kirby\Image\Darkroom;
Kirby\Image\Darkroom::$types['gd'] = 'Flokosiol\Focus\GdLib';
Kirby\Image\Darkroom::$types['im'] = 'Flokosiol\Focus\ImageMagick';
Kirby::plugin('flokosiol/focus', [
// 'components' => [
// 'thumb' => function (App $kirby, string $src, string $dst, array $options): string {
// if (isset($options['focus'])) {
// Kirby\Image\Darkroom::$types['gd'] = 'Flokosiol\Focus\GdLib';
// Kirby\Image\Darkroom::$types['im'] = 'Flokosiol\Focus\ImageMagick';
// }
// // @see kirby/config/components.php
// $core = require $kirby->root('kirby') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'components.php';
// return $core['thumb']($kirby, $src, $dst, $options);
// },
// ],
'fields' => [
'focus' => [
'props' => [
'value' => function ($value = '{"x":0.5,"y":0.5}') {
return $value;
}
],
'computed' => [
'isFileBlueprint' => function() {
$fileTypes = ['image','document','archive','code','video','audio'];
return in_array($this->model()->type(), $fileTypes);
},
'image' => function() {
if ($this->model()->type() == "image") {
return $this->model()->url();
}
else {
return false;
}
},
'video' => function() {
if ($this->model()->type() == "video") {
return [
'url' => $this->model()->url(),
'mime' => $this->model()->mime()
];
}
else {
return false;
}
}
]
]
],
'fileMethods' => [
'focusX' => function () {
return Flokosiol\Focus::coordinates($this, 'x');
},
'focusY' => function () {
return Flokosiol\Focus::coordinates($this, 'y');
},
'focusPercentageX' => function (int $roundTo = 1) {
$focusX = $this->focusX();
return ($roundTo * ceil($focusX * 100 / $roundTo));
},
'focusPercentageY' => function (int $roundTo = 1) {
$focusY = $this->focusY();
return ($roundTo * ceil($focusY * 100 / $roundTo));
},
'focusCrop' => function (int $width, int $height = null, $options = []) {
return Flokosiol\Focus::focusCrop($this, $width, $height, $options);
},
'focusSrcset' => function ($sizes = null) {
return Flokosiol\Focus::focusSrcset($this, $sizes);
},
'focusPreset' => function (string $preset) {
$config = $this->kirby()->option('flokosiol.focus.presets.' . $preset);
if (isset($config['width'])) {
$width = $config['width'];
$height = $config['height'] ?? null;
$options = $config['options'] ?? null;
return $this->focusCrop($width, $height, $options);
}
return '';
}
]
]);