diff --git a/php/Modules/Photo.php b/php/Modules/Photo.php index 8a3c9de8..ee1e8571 100755 --- a/php/Modules/Photo.php +++ b/php/Modules/Photo.php @@ -1059,7 +1059,26 @@ public function getInfo($url) { } // Read EXIF - if ($info['mime']=='image/jpeg') $exif = @exif_read_data($url, 'EXIF', false, false); + if ($info['mime']=='image/jpeg') { + $exif = false; + if(Settings::useExiftool()) { + Log::notice(Database::get(), __METHOD__, __LINE__, 'Using exiftool'); + $handle = @popen("exiftool -php -q $url 2>&1", 'r'); + $exiftool = @fread($handle, 8192); + @pclose($handle); + if (false!==$exiftool && strlen($exiftool) > 0) { + $exiftool = @eval('return ' . "$exiftool"); + if (is_array($exiftool) && is_array($exiftool[0])) { + $exif = $exiftool[0]; + } + } + } + // If exiftool is not available + // or using exiftool fails in any way fallback to exif_read_data + if (!is_array($exif)) { + $exif = @exif_read_data($url, 'EXIF', false, false); + } + } else $exif = false; // EXIF Metadata @@ -1071,9 +1090,11 @@ public function getInfo($url) { // ISO if (!empty($exif['ISOSpeedRatings'])) $return['iso'] = $exif['ISOSpeedRatings']; + else if (!empty($exif['ISO'])) $return['iso'] = trim($exif['ISO']); // Aperture if (!empty($exif['COMPUTED']['ApertureFNumber'])) $return['aperture'] = $exif['COMPUTED']['ApertureFNumber']; + else if (!empty($exif['Aperture'])) $return['aperture'] = 'f/' . trim($exif['Aperture']); // Make if (!empty($exif['Make'])) $return['make'] = trim($exif['Make']); @@ -1091,6 +1112,9 @@ public function getInfo($url) { $temp = $temp[0] / $temp[1]; $temp = round($temp, 1); $return['focal'] = $temp . ' mm'; + } else if (strpos($exif['FocalLength'], 'mm')!==false) { + $temp = substr($exif['FocalLength'], 0, strpos($exif['FocalLength'], '.')); + $return['focal'] = $temp . ' mm'; } else { $return['focal'] = $exif['FocalLength'] . ' mm'; } @@ -1107,6 +1131,7 @@ public function getInfo($url) { } if (!empty($exif['LensInfo'])) $return['lens'] = trim($exif['LensInfo']); + else if(!empty($exif['Lens'])) $return['lens'] = trim($exif['Lens']); // Lens field from Lightroom if ($return['lens'] == '' && !empty($exif['UndefinedTag:0xA434'])) $return['lens'] = trim($exif['UndefinedTag:0xA434']); diff --git a/php/Modules/Session.php b/php/Modules/Session.php index 432b61de..449c7404 100755 --- a/php/Modules/Session.php +++ b/php/Modules/Session.php @@ -54,6 +54,7 @@ public function init($public = true) { unset($return['config']['imagick']); unset($return['config']['plugins']); unset($return['config']['php_script_limit']); + unset($return['config']['useExiftool']); } diff --git a/php/Modules/Settings.php b/php/Modules/Settings.php index 11b3eed2..928dee90 100755 --- a/php/Modules/Settings.php +++ b/php/Modules/Settings.php @@ -349,4 +349,13 @@ public static function setDefaultLicense($license) { return false; } + /** + * @return bool Returns the useExiftool setting. + */ + public static function useExiftool() { + system('which exiftool 2>&1 > /dev/null', $status); + if ($status != 0) return false; + return (bool) (self::get()['useExiftool'] === '1'); + } + } diff --git a/php/database/update_030212.php b/php/database/update_030212.php new file mode 100644 index 00000000..f16dde6e --- /dev/null +++ b/php/database/update_030212.php @@ -0,0 +1,26 @@ +num_rows===0) { + + $query = Database::prepare($connection, "INSERT INTO `?` (`key`, `value`) VALUES ('useExiftool', '0')", array(LYCHEE_TABLE_SETTINGS)); + $result = Database::execute($connection, $query, 'update_030212', __LINE__); + + if ($result===false) Response::error('Could not add useExiftool to database!'); +} + + +// Set version +if (Database::setVersion($connection, 'update_030212')===false) Response::error('Could not update version of database!');