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
Changes from 1 commit
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;
system('which exiftool 2>&1 > /dev/null', $status);
ildyria marked this conversation as resolved.
Show resolved Hide resolved
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
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