Change the sort order
This commit is contained in:
@@ -29,12 +29,26 @@ def parse_args():
|
||||
parser.add_argument('--thumb-height', type=int, help='Thumbnail height in pixels')
|
||||
return parser.parse_args()
|
||||
|
||||
def get_image_date(path: Path):
|
||||
try:
|
||||
with Image.open(path) as img:
|
||||
exif = img._getexif()
|
||||
if exif:
|
||||
date_str = exif.get(36867) or exif.get(306) # DateTimeOriginal or DateTime
|
||||
if date_str:
|
||||
from datetime import datetime
|
||||
return datetime.strptime(date_str, '%Y:%m:%d %H:%M:%S')
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def collect_images(source_dir: Path):
|
||||
images = []
|
||||
for entry in sorted(source_dir.iterdir()):
|
||||
for entry in reversed(sorted(source_dir.iterdir())):
|
||||
if entry.is_file() and entry.suffix.lower() in IMAGE_EXTENSIONS:
|
||||
images.append(entry)
|
||||
return images
|
||||
return sorted(images,
|
||||
key=lambda img: get_image_date(img) or Path(img).stat().st_mtime)
|
||||
|
||||
def extract_metadata(image_path: Path):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user