Hello Kirby community,
I hope I might get some help here, as I am a beginner with PHP and cannot find a solution to my problem.
I have installed the k3-image-clip plugin and am currently writing my extension of this plugin to save the clipped image to the same path as the original while renaming it to include the ending “-clipped”.
I have now been able to get the hook working. I just extended the index.php of the k3-image-clip. It now shows an error message. All the details below.
Thanks for the help.
<?php
Kirby::plugin('mullema/k3-image-clip', [
'components' => [
'file::version' => include __DIR__ . '/components/file-version.php',
'thumb' => include __DIR__ . '/components/thumb.php'
],
'fields' => [
'image-clip' => include __DIR__ . '/fields/image-clip.php'
],
'fieldMethods' => [
'toImage' => include __DIR__ . '/fieldMethods/toImage.php',
'toImages' => include __DIR__ . '/fieldMethods/toImages.php',
],
'hooks' => [
'page.update:after' => function ($newPage, $oldPage) {
$image = $newPage->content()->images();
$oldFilename = $image->filename();
try {
$newFilename = $oldFilename . "-clipped";
$image->clip()->save($newFilename, $image->root());
$image->rename($newFilename);
echo ($image);
} catch (Exception $e) {
echo 'The file has not not been created';
}
}
]
]);
Message shown on save of image is:
- id: bild-home-business.jpg clip: width: 1392 height: 1800 left: 914 top: 0