Yeah, thank you very much,
altough, i’m not able to use it dynamically to apply the keywords to my HTML data-metadata-tag=""
I don’t really know how to retrieve that that here. And as soon as I try to make it dynamic I’m facing that error : exif_read_data(): Unable to open file in Kirby. I feel it has something to do with the media generated?
What I would like to do now, is to use the fetched keywords (from the metadata) in my panel with the tag field. It will be automatically filled and expandable.
Is there a way I can do that?
Thanks!
You could achieve this via a file.upload:after hook. In your hook, extract the metadata from the file and then use $file->update() to update the file meta data (in the Kirby sense of the word).
alright, this post quite helped so far and seem to be doing what I want to achieve.
My newbie question would be that I don’t know where to use this plugin code?
<?php
// Get keywords from IPTC data
function iptc_keywords($image) {
$size = getimagesize($image->url(), $info);
if(isset($info['APP13'])){
$iptc = iptcparse($info['APP13']);
// Get keywords
$keywords = '';
$keywordcount = count($iptc["2#025"]);
for ($i=0; $i < $keywordcount; $i++) {
$keywords .= $iptc['2#025'][$i].', ';
}
$keywords = rtrim($keywords,', ');
return $keywords;
}
};
kirby()->hook(['panel.file.upload'], function($image) {
if ($image->type() == 'image') {
// Get date created from exif data
$datecreated = $image->exif()->timestamp();
// Get keywords via function
$keywords = iptc_keywords($image);
// Update image metadata
$image->update(array(
'date' => $datecreated,
'tags' => $keywords
));
}
});
Alright,
Thanks a lot texnixe,
I managed to make something that can work somehow…
'hooks' => [
'file.create:after' => function ($image) {
if ($image->type() == 'image') {
// Get date created from exif data
$datecreated = $image->exif()->timestamp();
// Get keywords via function
function iptc_keywords($image)
{
if (isset($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
// Get keywords
$keywords = '';
$keywordcount = count($iptc["2#025"]);
for ($i = 0; $i < $keywordcount; $i++) {
$keywords .= $iptc['2#025'][$i] . ', ';
}
$keywords = rtrim($keywords, ', ');
return $keywords;
}
};
$keywords = iptc_keywords($image);
// Update image metadata
$image->update(array(
'date' => $datecreated,
'tags' => $keywords
));
}
}
],
There is still something that I can’t understand, it seems that the throw new Exception($image);
is throwing this error : Exception::__construct(): Passing null to parameter #1 ($message) of type string is deprecated
telling me that $image is null.