From 1f020dd6fbde02b1c0f89d24931cb9f4aecc99f6 Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Mon, 11 Feb 2019 00:29:47 +0100 Subject: [PATCH 1/6] Add usage of exiftool to get exif tags from camera manufactures like lens info Signed-off-by: Michael Rasmussen --- php/Modules/Photo.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/php/Modules/Photo.php b/php/Modules/Photo.php index 8a3c9de8..073dc0c5 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; + system('which exiftool 2>&1 > /dev/null', $status); + if ($status == 0) { + $handle = @popen("exiftool -php -q $url 2>&1", 'r'); + $exiftool = @fread($handle, 8192); + if (false!==$exiftool && strlen($exiftool) > 0) { + $exiftool = @eval('return ' . "$exiftool"); + @pclose($handle); + 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']); From c17bfd681400edb813cf510452cb4aa084dc57fa Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Mon, 11 Feb 2019 00:42:59 +0100 Subject: [PATCH 2/6] Fix possible leaking pclose Signed-off-by: Michael Rasmussen --- php/Modules/Photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/Modules/Photo.php b/php/Modules/Photo.php index 073dc0c5..79289ebf 100755 --- a/php/Modules/Photo.php +++ b/php/Modules/Photo.php @@ -1065,9 +1065,9 @@ public function getInfo($url) { if ($status == 0) { $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"); - @pclose($handle); if (is_array($exiftool) && is_array($exiftool[0])) { $exif = $exiftool[0]; } From 4a425737a2f898f4ccc9a13d19ef1ae737cc85bd Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Mon, 11 Feb 2019 15:15:24 +0100 Subject: [PATCH 3/6] Add user configuration to use Exiftool or not Signed-off-by: Michael Rasmussen --- php/Modules/Photo.php | 21 ++++++++++++--------- php/Modules/Session.php | 1 + php/Modules/Settings.php | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/php/Modules/Photo.php b/php/Modules/Photo.php index 79289ebf..e5332a74 100755 --- a/php/Modules/Photo.php +++ b/php/Modules/Photo.php @@ -1061,15 +1061,18 @@ public function getInfo($url) { // Read EXIF if ($info['mime']=='image/jpeg') { $exif = false; - system('which exiftool 2>&1 > /dev/null', $status); - if ($status == 0) { - $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(Settings::useExiftool()) { + Log::notice(Database::get(), __METHOD__, __LINE__, 'Using exiftool'); + system('which exiftool 2>&1 > /dev/null', $status); + if ($status == 0) { + $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]; + } } } } 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..427ab2e6 100755 --- a/php/Modules/Settings.php +++ b/php/Modules/Settings.php @@ -349,4 +349,20 @@ public static function setDefaultLicense($license) { return false; } + /** + * @return bool Returns the useExiftool setting. + */ + public static function useExiftool() { + return (bool) (self::get()['useExiftool'] === '1'); + } + + /** + * @return bool Set the useExiftool setting. + */ + public static function setUseExiftool($enable) { + Log::notice(Database::get(), __METHOD__, __LINE__, 'Change useExiftool to: ' . $enable); + if (self::set('useExiftool', $enable)===false) return false; + return true; + } + } From be61b8e9125f9383ae22927a6b02f1ba8698c67a Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Mon, 11 Feb 2019 15:34:05 +0100 Subject: [PATCH 4/6] Drop unused function Signed-off-by: Michael Rasmussen --- php/Modules/Settings.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/php/Modules/Settings.php b/php/Modules/Settings.php index 427ab2e6..c5de21cd 100755 --- a/php/Modules/Settings.php +++ b/php/Modules/Settings.php @@ -356,13 +356,4 @@ public static function useExiftool() { return (bool) (self::get()['useExiftool'] === '1'); } - /** - * @return bool Set the useExiftool setting. - */ - public static function setUseExiftool($enable) { - Log::notice(Database::get(), __METHOD__, __LINE__, 'Change useExiftool to: ' . $enable); - if (self::set('useExiftool', $enable)===false) return false; - return true; - } - } From ceab99b998e9dec2d419d95d338d2c8190ea035f Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Mon, 11 Feb 2019 15:40:10 +0100 Subject: [PATCH 5/6] Provide script for updating database Signed-off-by: Michael Rasmussen --- php/database/update_030212.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 php/database/update_030212.php 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!'); From 5d2997223712b8354e9b9760042368554d12b7cd Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Mon, 11 Feb 2019 15:55:16 +0100 Subject: [PATCH 6/6] Move check for exiftool to useExiftool function Signed-off-by: Michael Rasmussen --- php/Modules/Photo.php | 17 +++++++---------- php/Modules/Settings.php | 2 ++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/php/Modules/Photo.php b/php/Modules/Photo.php index e5332a74..ee1e8571 100755 --- a/php/Modules/Photo.php +++ b/php/Modules/Photo.php @@ -1063,16 +1063,13 @@ public function getInfo($url) { $exif = false; if(Settings::useExiftool()) { Log::notice(Database::get(), __METHOD__, __LINE__, 'Using exiftool'); - system('which exiftool 2>&1 > /dev/null', $status); - if ($status == 0) { - $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]; - } + $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]; } } } diff --git a/php/Modules/Settings.php b/php/Modules/Settings.php index c5de21cd..928dee90 100755 --- a/php/Modules/Settings.php +++ b/php/Modules/Settings.php @@ -353,6 +353,8 @@ public static function setDefaultLicense($license) { * @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'); }