This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.php
executable file
·47 lines (45 loc) · 1.6 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
<?php
function autoresize($file) {
$maxWidth = option('medienbaecker.autoresize.maxWidth');
$maxHeight = option('medienbaecker.autoresize.maxHeight');
$quality = option('medienbaecker.autoresize.quality');
$excludeTemplates = option('medienbaecker.autoresize.excludeTemplates');
$excludePages = option('medienbaecker.autoresize.excludePages');
$excludedByTemplate = false;
$excludedByPage = false;
if($file->page()) {
if(!empty($excludeTemplates)) $excludedByTemplate = in_array($file->page()->intendedTemplate(), $excludeTemplates);
if(!empty($excludePages)) $excludedByPage = in_array($file->page()->uid(), $excludePages);
}
if($file->isResizable() && !$excludedByTemplate && !$excludedByPage) {
if($file->width() > $maxWidth || $file->height() > $maxHeight){
try {
kirby()->thumb($file->root(), $file->root(), [
'width' => $maxWidth,
'height' => $maxHeight,
'quality' => $quality
]);
}
catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
}
}
Kirby::plugin('medienbaecker/autoresize', [
'options' => [
'maxWidth' => 2000,
'maxHeight' => 2000,
'quality' => 90,
'excludeTemplates' => [],
'excludePages' => []
],
'hooks' => [
'file.create:after' => function ($file) {
autoresize($file);
},
'file.replace:after' => function ($newFile, $oldFile) {
autoresize($newFile);
}
]
]);