There are some posts around on this one, none conclusive for me or too old, like this one.
A client wants to have a copyright text in their images EXIF or IPTC metadata.
Either the client adds this on image creation, then kirby respects it when thumb’ing it (which does not seem to be the case at least here locally with GD )
OR
I write the metadata programatically when thumb’ing the image (although not sure where, in the template itself when calling resize or similar?)
What would be a reccomended, plausible approach here to achieve this ?
If you want to add EXIF data to Kirby’s file metadata, then I would do this using a hook on image upload. There is no hook to hook into image thumbing.
As regards the im driver, setting the strip option to false in thumb options should preserve EXIF data.
I tested JPG files. On a website for a photographer I want to preserve the copyright metadata in the photos. Can this only be achieved via a custom thumb driver?
so if you encounter a thumb that does not have exif meta data, then go to the source image and re-apply that to the thumb. that might be easier than a custom driver.
if (!$thumb->exif() || empty($thumb->exif()->data()) {
if ($thumb->original()->exif() && !empty($thumb->original()->exif()->data())) {
\transferIptcExif2File($thumb->original()->root(), $thumb->root());
}
}
This could be a quick fix, thank you! (In the long run, it would probably be better to develop a plugin, as in my projects copyright metadata in images usually needs to be preserved.) Can you maybe help me one step further and tell me how exactly I can apply your code snippet?
Here the code snippet from my template in which the thumb is created:
sorry about the confusion. you can not mix if statements terminated with : and {. but since you will be using the exif copy a few times it might be best to put it in a custom filemethod.
site/plugins/exit/index.php
<?php
// TODO: copy and paste the transferIptcExif2File function from the link to php.net above.
Kirby::plugin('exif/plugin', [
'fileMethods' => [
'transferIptcExif2File' => function () {
if(!$this->exif() || empty($this->exif()->data()) {
if ($this->original()->exif() && !empty($this->original()->exif()->data())) {
\transferIptcExif2File($this->original()->root(), $this->root());
}
}
return $this;
}
]
]);
The problem here is that $thumb is not a file object but a FileVersion object, so calling a file method will not work. You would have to implement this as a normal function.
For not to have to adapt code snippets in a lot of templates, I have nevertheless created a custom thumb driver plugin as @texnixe suggested, which seems to work at first impression. For that I’ve copied and adapted ImageMagick.php from Kirby’s Darkroom:
I removed the command strip and
replaced the command thumbnail (because it comes with an implied strip operation) by resize.