$sFile) { printf("Processing %s (%d/%d)...\n", $sFile, $i, $iFiles); // Regenerate JPG and DNG file paths $sJpgPath = sprintf('%s%s%s.jpg', $sDir, DIRECTORY_SEPARATOR, $sFile); $sDngPath = sprintf('%s%s%s.dng', $sDir, DIRECTORY_SEPARATOR, $sFile); // Read from JPG file printf(" > Reading from JPG file.\n"); $oFileEntity = $oReader->files($sJpgPath)->first(); $oReader->reset(); // Extract desired GPS tags $aData = $aMetadataBag = array(); $aKeys = array( 'GPS:GPSAltitude' => 'altitude', 'GPS:GPSLongitude' => 'longitude', 'GPS:GPSLatitude' => 'latitude', 'GPS:GPSImgDirection' => 'direction'); // Loop over all metadata printf(" > Parsing metadata.\n"); foreach ($oFileEntity as $oMetaData) { $oTag = $oMetaData->getTag(); $sTag = $oTag->getTagname(); $oValue = $oMetaData->getValue(); // Store desired tags if (array_key_exists($sTag, $aKeys)) { $aData[$aKeys[$sTag]] = $oValue; } // Store all GPS tags in metadata bag if (strpos($sTag, 'GPS:') !== false) { $aMetadataBag[] = $oMetaData; } } // Check presence of GPS data if (empty($aData)) { printf(" > No GPS data present!\n"); continue; } // Convert values to floats $aData = array_map(function ($sValue) { return floatval($sValue->asString()); }, $aData); // Write to DNG file printf(" > Writing to DNG file.\n"); $oWriter->write($sDngPath, new MetadataBag($aMetadataBag)); }