Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

Add usage of exiftool to get exif tags from camera manufactures #189

Merged
merged 6 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion php/Modules/Photo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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']);
Expand All @@ -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';
}
Expand All @@ -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']);
Expand Down
1 change: 1 addition & 0 deletions php/Modules/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);

}

Expand Down
9 changes: 9 additions & 0 deletions php/Modules/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
ildyria marked this conversation as resolved.
Show resolved Hide resolved
}

}
26 changes: 26 additions & 0 deletions php/database/update_030212.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* Update to version 3.2.12
*/

use Lychee\Modules\Database;
use Lychee\Modules\Response;

// Add useExiftool to settings
$query = Database::prepare($connection, "SELECT `key` FROM `?` WHERE `key` = 'useExiftool' LIMIT 1", array(LYCHEE_TABLE_SETTINGS));
$result = Database::execute($connection, $query, 'update_030212', __LINE__);

if ($result===false) Response::error('Could not get useExiftool from database!');

if ($result->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!');