I'm trying to overwrite/save JPEG file's EXIF data using https://github.com/lsolesen/pel library. Here is the code that has to save new EXIF data:
use lsolesen\pel\PelJpeg;
use lsolesen\pel\PelTag;
use lsolesen\pel\PelEntryAscii;
...
$pelJpeg = new PelJpeg(Yii::getAlias('@str-set') . "/$this->hash.jpg");
$pelExif = $pelJpeg->getExif();
if ($pelExif == null) {
$pelExif = new PelExif();
$pelJpeg->setExif($pelExif);
}
$pelTiff = $pelExif->getTiff();
if ($pelTiff == null) {
$pelTiff = new PelTiff();
$pelExif->setTiff($pelTiff);
}
$pelIfd0 = $pelTiff->getIfd();
if ($pelIfd0 == null) {
$pelIfd0 = new PelIfd(PelIfd::IFD0);
$pelTiff->setIfd($pelIfd0);
}
$pelIfd0->addEntry(new PelEntryAscii(
PelTag::IMAGE_DESCRIPTION, $this->description
)
);
$pelIfd0->addEntry(new PelEntryAscii(
PelTag::XP_TITLE, $this->title
)
);
$keywords = [];
foreach ($this->keywords as $keyword)
$keywords[] = $keyword->title;
$kw_string = implode(", ", $keywords);
$pelIfd0->addEntry(new PelEntryAscii(
PelTag::XP_KEYWORDS, $kw_string
)
);
$pelJpeg->saveFile(Yii::getAlias('@str-set') . "/$this->hash.jpg");
...
Here is sample tags:
icon, vector, background
But I'm getting the file without any tags, description or title saved.
So the result has to be like this:
But getting this
What am I doing wrong?
Most of these field belongs to IPTC block.
I recommend You to use iptc-jpeg package to comfortably update these fields.