commit
b9a7bd1056
@ -239,7 +239,7 @@ final class Photo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save to DB
|
// Save to DB
|
||||||
$values = array(LYCHEE_TABLE_PHOTOS, $id, $info['title'], $photo_name, $info['description'], '', $info['type'], $info['width'], $info['height'], $info['size'], $info['iso'], $info['aperture'], $info['make'], $info['model'], $info['shutter'], $info['focal'], $info['takestamp'], $path_thumb, $albumID, $public, $star, $checksum, $medium);
|
$values = array(LYCHEE_TABLE_PHOTOS, $id, $info['title'], $photo_name, $info['description'], $info['tags'], $info['type'], $info['width'], $info['height'], $info['size'], $info['iso'], $info['aperture'], $info['make'], $info['model'], $info['shutter'], $info['focal'], $info['takestamp'], $path_thumb, $albumID, $public, $star, $checksum, $medium);
|
||||||
$query = Database::prepare(Database::get(), "INSERT INTO ? (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum, medium) VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')", $values);
|
$query = Database::prepare(Database::get(), "INSERT INTO ? (id, title, url, description, tags, type, width, height, size, iso, aperture, make, model, shutter, focal, takestamp, thumbUrl, album, public, star, checksum, medium) VALUES ('?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?')", $values);
|
||||||
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||||
|
|
||||||
@ -307,7 +307,7 @@ final class Photo {
|
|||||||
$newUrl2x = LYCHEE_UPLOADS_THUMB . $photoName[0] . '@2x.jpeg';
|
$newUrl2x = LYCHEE_UPLOADS_THUMB . $photoName[0] . '@2x.jpeg';
|
||||||
|
|
||||||
// Create thumbnails with Imagick
|
// Create thumbnails with Imagick
|
||||||
if(extension_loaded('imagick')&&Settings::get()['imagick']==='1') {
|
if(Settings::hasImagick()) {
|
||||||
|
|
||||||
// Read image
|
// Read image
|
||||||
$thumb = new Imagick();
|
$thumb = new Imagick();
|
||||||
@ -730,36 +730,8 @@ final class Photo {
|
|||||||
$return['type'] = $info['mime'];
|
$return['type'] = $info['mime'];
|
||||||
$return['width'] = $info[0];
|
$return['width'] = $info[0];
|
||||||
$return['height'] = $info[1];
|
$return['height'] = $info[1];
|
||||||
|
|
||||||
// Size
|
|
||||||
$size = filesize($url)/1024;
|
|
||||||
if ($size>=1024) $return['size'] = round($size/1024, 1) . ' MB';
|
|
||||||
else $return['size'] = round($size, 1) . ' KB';
|
|
||||||
|
|
||||||
// IPTC Metadata Fallback
|
|
||||||
$return['title'] = '';
|
$return['title'] = '';
|
||||||
$return['description'] = '';
|
$return['description'] = '';
|
||||||
|
|
||||||
// IPTC Metadata
|
|
||||||
if(isset($iptcArray['APP13'])) {
|
|
||||||
|
|
||||||
$iptcInfo = iptcparse($iptcArray['APP13']);
|
|
||||||
if (is_array($iptcInfo)) {
|
|
||||||
|
|
||||||
$temp = @$iptcInfo['2#105'][0];
|
|
||||||
if (isset($temp)&&strlen($temp)>0) $return['title'] = $temp;
|
|
||||||
|
|
||||||
$temp = @$iptcInfo['2#120'][0];
|
|
||||||
if (isset($temp)&&strlen($temp)>0) $return['description'] = $temp;
|
|
||||||
|
|
||||||
$temp = @$iptcInfo['2#005'][0];
|
|
||||||
if (isset($temp)&&strlen($temp)>0&&$return['title']==='') $return['title'] = $temp;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXIF Metadata Fallback
|
|
||||||
$return['orientation'] = '';
|
$return['orientation'] = '';
|
||||||
$return['iso'] = '';
|
$return['iso'] = '';
|
||||||
$return['aperture'] = '';
|
$return['aperture'] = '';
|
||||||
@ -768,9 +740,50 @@ final class Photo {
|
|||||||
$return['shutter'] = '';
|
$return['shutter'] = '';
|
||||||
$return['focal'] = '';
|
$return['focal'] = '';
|
||||||
$return['takestamp'] = 0;
|
$return['takestamp'] = 0;
|
||||||
|
$return['lens'] = '';
|
||||||
|
$return['tags'] = array();
|
||||||
|
$return['position'] = '';
|
||||||
|
$return['latitude'] = '';
|
||||||
|
$return['longitude'] = '';
|
||||||
|
$return['altitude'] = '';
|
||||||
|
|
||||||
|
// Size
|
||||||
|
$size = filesize($url)/1024;
|
||||||
|
if ($size>=1024) $return['size'] = round($size/1024, 1) . ' MB';
|
||||||
|
else $return['size'] = round($size, 1) . ' KB';
|
||||||
|
|
||||||
|
// IPTC Metadata
|
||||||
|
// See https://www.iptc.org/std/IIM/4.2/specification/IIMV4.2.pdf for mapping
|
||||||
|
if(isset($iptcArray['APP13'])) {
|
||||||
|
|
||||||
|
$iptcInfo = iptcparse($iptcArray['APP13']);
|
||||||
|
if (is_array($iptcInfo)) {
|
||||||
|
|
||||||
|
// Title
|
||||||
|
if (!empty($iptcInfo['2#105'][0])) $return['title'] = $iptcInfo['2#105'][0];
|
||||||
|
else if (!empty($iptcInfo['2#005'][0])) $return['title'] = $iptcInfo['2#005'][0];
|
||||||
|
|
||||||
|
// Description
|
||||||
|
if (!empty($iptcInfo['2#120'][0])) $return['description'] = $iptcInfo['2#120'][0];
|
||||||
|
|
||||||
|
// Tags
|
||||||
|
if (!empty($iptcInfo['2#025'])) $return['tags'] = implode(',', $iptcInfo['2#025']);
|
||||||
|
|
||||||
|
// Position
|
||||||
|
$fields = array();
|
||||||
|
if (!empty($iptcInfo['2#090'])) $fields[] = trim($iptcInfo['2#090'][0]);
|
||||||
|
if (!empty($iptcInfo['2#092'])) $fields[] = trim($iptcInfo['2#092'][0]);
|
||||||
|
if (!empty($iptcInfo['2#095'])) $fields[] = trim($iptcInfo['2#095'][0]);
|
||||||
|
if (!empty($iptcInfo['2#101'])) $fields[] = trim($iptcInfo['2#101'][0]);
|
||||||
|
|
||||||
|
if (!empty($fields)) $return['position'] = implode(', ', $fields);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Read EXIF
|
// Read EXIF
|
||||||
if ($info['mime']=='image/jpeg') $exif = @exif_read_data($url, 'EXIF', 0);
|
if ($info['mime']=='image/jpeg') $exif = exif_read_data($url, 'EXIF', 0);
|
||||||
else $exif = false;
|
else $exif = false;
|
||||||
|
|
||||||
// EXIF Metadata
|
// EXIF Metadata
|
||||||
@ -779,34 +792,37 @@ final class Photo {
|
|||||||
if (isset($exif['Orientation'])) $return['orientation'] = $exif['Orientation'];
|
if (isset($exif['Orientation'])) $return['orientation'] = $exif['Orientation'];
|
||||||
else if (isset($exif['IFD0']['Orientation'])) $return['orientation'] = $exif['IFD0']['Orientation'];
|
else if (isset($exif['IFD0']['Orientation'])) $return['orientation'] = $exif['IFD0']['Orientation'];
|
||||||
|
|
||||||
$temp = @$exif['ISOSpeedRatings'];
|
if (!empty($exif['ISOSpeedRatings'])) $return['iso'] = $exif['ISOSpeedRatings'];
|
||||||
if (isset($temp)) $return['iso'] = $temp;
|
|
||||||
|
|
||||||
$temp = @$exif['COMPUTED']['ApertureFNumber'];
|
if (!empty($exif['COMPUTED']['ApertureFNumber'])) $return['aperture'] = $exif['COMPUTED']['ApertureFNumber'];
|
||||||
if (isset($temp)) $return['aperture'] = $temp;
|
|
||||||
|
|
||||||
$temp = @$exif['Make'];
|
if (!empty($exif['Make'])) $return['make'] = trim($exif['Make']);
|
||||||
if (isset($temp)) $return['make'] = trim($temp);
|
|
||||||
|
|
||||||
$temp = @$exif['Model'];
|
if (!empty($exif['Model'])) $return['model'] = trim($exif['Model']);
|
||||||
if (isset($temp)) $return['model'] = trim($temp);
|
|
||||||
|
|
||||||
$temp = @$exif['ExposureTime'];
|
if (!empty($exif['ExposureTime'])) $return['shutter'] = $exif['ExposureTime'] . ' s';
|
||||||
if (isset($temp)) $return['shutter'] = $exif['ExposureTime'] . ' s';
|
|
||||||
|
|
||||||
$temp = @$exif['FocalLength'];
|
if (!empty($exif['FocalLength'])) {
|
||||||
if (isset($temp)) {
|
if (strpos($exif['FocalLength'], '/')!==false) {
|
||||||
if (strpos($temp, '/')!==FALSE) {
|
$temp = explode('/', $exif['FocalLength'], 2);
|
||||||
$temp = explode('/', $temp, 2);
|
|
||||||
$temp = $temp[0] / $temp[1];
|
$temp = $temp[0] / $temp[1];
|
||||||
$temp = round($temp, 1);
|
$temp = round($temp, 1);
|
||||||
$return['focal'] = $temp . ' mm';
|
$return['focal'] = $temp . ' mm';
|
||||||
}
|
}
|
||||||
$return['focal'] = $temp . ' mm';
|
else $return['focal'] = $exif['FocalLength'] . ' mm';
|
||||||
}
|
}
|
||||||
|
|
||||||
$temp = @$exif['DateTimeOriginal'];
|
if (!empty($exif['DateTimeOriginal'])) $return['takestamp'] = strtotime($exif['DateTimeOriginal']);
|
||||||
if (isset($temp)) $return['takestamp'] = strtotime($temp);
|
|
||||||
|
// Lens field from Lightroom
|
||||||
|
if (!empty($exif['UndefinedTag:0xA434'])) $return['lens'] = trim($exif['UndefinedTag:0xA434']);
|
||||||
|
|
||||||
|
|
||||||
|
// Deal with GPS coordinates
|
||||||
|
if (!empty($exif['GPSLatitude']) && !empty($exif['GPSLatitudeRef']))
|
||||||
|
$return['latitude'] = getGPSCoordinate($exif['GPSLatitude'], $exif['GPSLatitudeRef']);
|
||||||
|
if (!empty($exif['GPSLongitude']) && !empty($exif['GPSLongitudeRef']))
|
||||||
|
$return['longitude'] = getGPSCoordinate($exif['GPSLongitude'], $exif['GPSLongitudeRef']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +221,13 @@ final class Settings {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array Returns the Imagick setting.
|
||||||
|
*/
|
||||||
|
public static function hasImagick() {
|
||||||
|
return (bool)(extension_loaded('imagick') && self::get()['imagick'] === '1');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
28
php/helpers/getGPSCoordinate.php
Normal file
28
php/helpers/getGPSCoordinate.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the normalized coordinate from EXIF array.
|
||||||
|
* @return string Normalized coordinate as float number (degrees).
|
||||||
|
*/
|
||||||
|
function getGPSCoordinate($coordinate, $ref) {
|
||||||
|
$degrees = count($coordinate) > 0 ? formattedToFloatGPS($coordinate[0]) : 0;
|
||||||
|
$minutes = count($coordinate) > 1 ? formattedToFloatGPS($coordinate[1]) : 0;
|
||||||
|
$seconds = count($coordinate) > 2 ? formattedToFloatGPS($coordinate[2]) : 0;
|
||||||
|
|
||||||
|
$flip = ($ref == 'W' || $ref == 'S') ? -1 : 1;
|
||||||
|
|
||||||
|
return $flip * ($degrees + (float)$minutes / 60 + (float)$seconds / 3600);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formattedToFloatGPS($coordinate) {
|
||||||
|
$parts = explode('/', $coordinate, 2);
|
||||||
|
|
||||||
|
if (count($parts) <= 0)
|
||||||
|
return 0;
|
||||||
|
if (count($parts) == 1)
|
||||||
|
return $parts[0];
|
||||||
|
|
||||||
|
return (float)$parts[0] / $parts[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -22,6 +22,7 @@ require(__DIR__ . '/autoload.php');
|
|||||||
require(__DIR__ . '/helpers/fastImageCopyResampled.php');
|
require(__DIR__ . '/helpers/fastImageCopyResampled.php');
|
||||||
require(__DIR__ . '/helpers/generateID.php');
|
require(__DIR__ . '/helpers/generateID.php');
|
||||||
require(__DIR__ . '/helpers/getExtension.php');
|
require(__DIR__ . '/helpers/getExtension.php');
|
||||||
|
require(__DIR__ . '/helpers/getGPSCoordinate.php');
|
||||||
require(__DIR__ . '/helpers/getGraphHeader.php');
|
require(__DIR__ . '/helpers/getGraphHeader.php');
|
||||||
require(__DIR__ . '/helpers/getHashedString.php');
|
require(__DIR__ . '/helpers/getHashedString.php');
|
||||||
require(__DIR__ . '/helpers/hasPermissions.php');
|
require(__DIR__ . '/helpers/hasPermissions.php');
|
||||||
|
Loading…
Reference in New Issue
Block a user