Improve sorting by date in ImageDrawer

This ensures that, if available, we'll sort using the date the file was created rather than modified date. Modified will be used as a fallback.
This commit is contained in:
Jared Therriault
2025-12-16 19:43:52 -08:00
parent a107e94efe
commit 71a89500bb
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ def create_familiar_dictionaries(names, type, image_extension_filter, info_exten
# logger.info(f"file_name_no_ext, file_ext: {file_name_no_ext, file_ext}")
# Get time of creation since the last epoch, in seconds
file_age = os.path.getctime(file_path)
file_age = get_creation_time(file_path)
file_path = file_path.replace("\\", "/")
# logger.info(f'file_path: {file_path}')
+8
View File
@@ -389,3 +389,11 @@ def is_pil_image(obj):
# Check if an object is a PyTorch tensor
def is_torch_tensor(obj):
return isinstance(obj, torch.Tensor)
def get_creation_time(file_path):
"""Get file creation time if available, otherwise fallback to modification time."""
try:
stat = os.stat(file_path)
return stat.st_birthtime # Works on some Linux filesystems
except AttributeError:
return os.path.getmtime(file_path)