Hi there,
I’m trying to resize images on upload via the panel, but I want to maintain the metadata stored in the image. I’ve gone about this using a hook and custom plugin based off another post in the forum and it resizes the image but doesn’t maintain the metadata and I just can’t quite figure out what I’m doing wrong so any advice would be appreciated.
site/config/config.php
'hooks' => [
'file.create:after' => function ($file) {
// Orginal file root location
$orginalFileLocation = $file->root();
// Create Resized Image
$thumbnail = $file->thumb(['width' => 2048]);
// Copy EXIF Data to Thumbnail
$file->transferIptcExif2File($thumbnail);
// Overwrite Orginal File
$thumbnail->move($orginalFileLocation, true);
}
],
site/plugins/thumbs/index.php
<?php
// Here I’ve inserted the transferIptcExif2File function from https://www.php.net/manual/en/function.iptcembed.php#113877
Kirby::plugin('exif/plugin', [
'fileMethods' => [
'transferIptcExif2File' => function($original, $thumb) {
if(!$thumb->exif() || empty($thumb->exif()->data())) {
if ($original->exif() && !empty($original->exif()->data())) {
transferIptcExif2File($original->root(), $thumb->root());
}
}
return $thumb;
}
]
]);
?>