I'm trying to figure out how to add IPTC/City & IPTC/State info to the end of my description on image import. Basically I want my location info searchable in the database. Is it possible to import three fields into one? I think the answer lies in EXIF/ExifDescriptionOption.inc around #115 but I can't figure it out. Can someone help with the code? Here's the original.
Quote:
$itemDescription = '';
if (!empty($exifData[$itemId]['IPTC/Caption']['value'])) {
$itemDescription = $exifData[$itemId]['IPTC/Caption']['value'];
}
else if (!empty($exifData[$itemId]['ImageDescription']['value'])) {
$itemDescription = $exifData[$itemId]['ImageDescription']['value'];
}
else if (!empty($exifData[$itemId]['UserComment']['value'])) {
$itemDescription = $exifData[$itemId]['UserComment']['value'];
}
Thanks. -Matt
Posts: 40
Can I use CONCAT for this? I need ['IPTC/City']','['IPTC/ProvinceState'] at the end of ['IPTC/Caption'].
Any guidance on this is really appreciated.
Posts: 16503
AFAIK, the EXIF/IPTC info is not stored in the database and actually read every time the image is loaded. Which is one reason it's advised to not use the EXIF module on a heavily trafficked site as it will become a huge performance hit.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 16503
Oh wait, I think I see what you're doing. So you're having that info imported into Gallery's description? I don't know the best approach to do that in the code.
I don't think you can use "CONCAT" for that as I don't think it's a valid PHP function, but...
http://php.net/manual/en/language.operators.string.php
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 40
That's what I'm looking for! I added a condition to grab the city & state info unless it's empty. Here's my change for the curious. Line #64 of ExifDescriptionOption.inc
Add
Line #117 change
Thanks for the help. Works great in the search.
Posts: 4
cron enhancement for adding images with IPTC data, custom fields and watermarking:
change part that import classes to add more needed classes
//import needed Gallery classes GalleryCoreApi::requireOnce('modules/core/classes/GalleryController.class'); GalleryCoreApi::requireOnce('modules/core/classes/GalleryView.class'); GalleryCoreApi::requireOnce('modules/core/ItemAdd.inc'); GalleryCoreApi::requireOnce('modules/itemadd/ItemAddFromServer.inc'); GalleryCoreApi::requireOnce('modules/exif/module.inc'); GalleryCoreApi::requireOnce('modules/exif/classes/ExifExtractor.class'); GalleryCoreApi::requireOnce('modules/customfield/classes/CustomFieldHelper.class');change FOREACH loop that adds items to process IPTC to Description, IPTC to custom fields (in this example Author name and Country name from IPTC populates values for Custom Fields) and to automatically watermark images.
$i = 0; foreach ($files as $file) { try { $ret = $this->itemAdd->addItem($this->album_id, $file, false, $this->text_fields, $this->status, $this->error); $itemId = $this->status['addedFiles'][$i]['id']; $i++; $this->check($ret); $exifExtractor = new ExifExtractor(); $exifData = $exifExtractor->getMetaData(array($itemId)); // load gallery item list ($ret, $item) = GalleryCoreApi::loadEntitiesById($itemId, 'GalleryItem'); if ($ret) { return array($ret, null); } // lock gallery item list ($ret, $lockId) = GalleryCoreApi::acquireWriteLock(array($itemId)); if ($ret) { return array($ret, null, null); } // set properties $item->setDescription($exifData[1][$itemId]['IPTC/Caption']['value']); $item->setKeywords($exifData[1][$itemId]['IPTC/Keywords']['value']); // save $ret = $item->save(); // unlock gallery item if ($ret) { GalleryCoreApi::releaseLocks(array($lockId)); return array($ret, null, null); } $ret = GalleryCoreApi::releaseLocks(array($lockId)); if ($ret) { return array($ret, null, null); } // set custom parameters: author, country $extraParams = array( 'Country' => $exifData[1][$itemId]['IPTC/CountryName']['value'], 'Author' => $exifData[1][$itemId]['IPTC/Byline']['value'] ); CustomFieldHelper::setCustomFieldValues($itemId, $extraParams); // add watermark to resized image // load watermark images GalleryCoreApi::requireOnce('modules/watermark/classes/WatermarkHelper.class'); list ($ret, $watermarks) = WatermarkHelper::fetchWatermarks(); $watermark = array_shift($watermarks); $which = array( DERIVATIVE_TYPE_IMAGE_PREFERRED => false, DERIVATIVE_TYPE_IMAGE_RESIZE => true, DERIVATIVE_TYPE_IMAGE_THUMBNAIL => false ); $ret = WatermarkHelper::watermarkItem($watermark, $item, $watermark->xPercentage, $watermark->yPercentage, $which); if ($ret) { return array($ret, null, null, null); } } catch (Exception $x) { $this->log_error($x->getMessage() . ': ' . $x->getTraceAsString()); } }