Browse Source

add exif and iptc support

master
filesite 2 weeks ago
parent
commit
fd1856aaa6
  1. 4
      conf/app.php
  2. 68
      lib/DirScanner.php
  3. 6
      themes/beauty/views/site/index.php

4
conf/app.php

@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
* Config
*/
$configs = array(
'version' => '0.3.8',
'releaseDate' => '2024-10-31',
'version' => '0.3.9',
'releaseDate' => '2024-11-09',
'showVersion' => false, //默认不显示版本号和发布日期
'default_timezone' => 'Asia/Hong_Kong', //timezone, check more: https://www.php.net/manual/en/timezones.asia.php

68
lib/DirScanner.php

@ -27,6 +27,12 @@ Class DirScanner { @@ -27,6 +27,12 @@ Class DirScanner {
'description' => '描述',
'keywords' => '关键词',
'snapshot' => '快照图片',
'original_ctime' => '照片拍摄时间',
//TODO: 待启用
'exif' => '照片EXIF信息',
'iptc' => '照片IPTC信息',
);
private $rootDir; //当前扫描的根目录
private $webRoot = '/content/'; //网站静态文件相对路径的根目录
@ -53,6 +59,16 @@ Class DirScanner { @@ -53,6 +59,16 @@ Class DirScanner {
'm3u8', //视频
);
protected $exifSupportFileExtensions = array(
'jpg', //图片
'jpeg', //图片
);
protected $iptcSupportFileExtensions = array(
'jpg', //图片
'jpeg', //图片
);
//暂未使用
/*
protected $maxReadFilesize = array( //默认每种文件读取内容最大大小
@ -230,6 +246,49 @@ Class DirScanner { @@ -230,6 +246,49 @@ Class DirScanner {
return $data;
}
//format: Ymd
//example: 20240322
//return: timestamp
private function getCreateDateFromIPTCMeta($realpath) {
$createTime = 0;
try {
if (function_exists('getimagesize') && function_exists('iptcparse')) {
$size = getimagesize($realpath, $info);
if(!empty($info['APP13'])) {
$iptc = iptcparse($info['APP13']);
if (!empty($iptc['2#055'])) {
$createTime = strtotime($iptc['2#055'][0]);
}
}
}
}catch(Exception $e) {
//do nothing
}
return $createTime;
}
//format: Y:m:d H:i:s
//example: 2024:03:22 00:23:02
//return: timestamp
private function getCreateDateFromExifMeta($realpath) {
$createTime = 0;
try {
if (function_exists('exif_read_data')) {
$exif = exif_read_data($realpath, 0, true);
if(!empty($exif['EXIF']['DateTimeOriginal'])) {
$createTime = strtotime($exif['EXIF']['DateTimeOriginal']);
}
}
}catch(Exception $e) {
//do nothing
}
return $createTime;
}
//根据路径生成文件数组,兼容URL文件
private function getFileData($realpath) {
$id = $this->getId($realpath);
@ -255,6 +314,15 @@ Class DirScanner { @@ -255,6 +314,15 @@ Class DirScanner {
if ($extension == 'url') {
$data['shortcut'] = $this->parseShortCuts($realpath, $filename);
}else if (in_array($extension, $this->exifSupportFileExtensions) || in_array($extension, $this->iptcSupportFileExtensions)) {
$photo_create_time = $this->getCreateDateFromExifMeta($realpath);
if ($photo_create_time == 0) {
$photo_create_time = $this->getCreateDateFromIPTCMeta($realpath);
}
if ($photo_create_time > 0) {
$data['original_ctime'] = $photo_create_time;
}
}
return $data;

6
themes/beauty/views/site/index.php

@ -326,10 +326,14 @@ eof; @@ -326,10 +326,14 @@ eof;
}
//图片、视频显示文件修改日期
$title = Common::getDateFromString($file['filename']);
if (!empty($file['original_ctime'])) { //优先使用照片的拍摄日期
$title = '摄于' . date('Y-m-d', $file['original_ctime']);
}else {
$title = Common::getDateFromString($file['filename']); //根据文件名获取拍摄日期
if (empty($title) && !empty($file['fstat']['mtime']) && !empty($file['fstat']['ctime'])) {
$title = date('Y-m-d', min($file['fstat']['mtime'], $file['fstat']['ctime']));
}
}
if (in_array($file['extension'], $imgExts)) {
//缩略图

Loading…
Cancel
Save