summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-06-15 11:50:34 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-06-15 11:50:34 +0200
commite5a19cdece0f1fad76611dc6d06764d471b9d526 (patch)
tree71860e841690e63679a8c557c5fb40e4c0d9679c
parentb85a07ee83b366687aba3408c3076b29ca88b8e8 (diff)
re-use existing thumbnails if present; remove no-longer-required ones
-rwxr-xr-xbin/pyggle85
1 files changed, 48 insertions, 37 deletions
diff --git a/bin/pyggle b/bin/pyggle
index 4b88749..81df0f1 100755
--- a/bin/pyggle
+++ b/bin/pyggle
@@ -286,6 +286,7 @@ class Thumbnail:
with_gps=False,
group_key_template=None,
file_key_template=None,
+ have_thumbnail=dict(),
):
self.filename = filename
self.jpegname = None
@@ -333,43 +334,45 @@ class Thumbnail:
if not self.thumbname.lower().endswith((".jpeg", ".jpg")):
self.thumbname += ".jpg"
- if not filename.lower().endswith((".cr2", ".cr3", ".rw2")):
- im = rotate_image(im, self.exif_tag)
-
- im.thumbnail((self.size * 4, self.size * 2))
- im = im.convert("RGB")
- im.save(self.thumbname, "JPEG")
-
- if filename.lower().endswith((".cr2", ".cr3", ".rw2")):
- try:
- jpegname = f".thumbnails/{thumb_filename}.p.jpg"
- subprocess.run(
- [
- "exiftool",
- "-quiet",
- "-binary",
- "-tagOut!",
- jpegname,
- "-PreviewImage",
- filename,
- ]
- )
- # JpgFromRaw tends to have higher resolution, so overwrite PreviewImage if it is present
- subprocess.run(
- [
- "exiftool",
- "-quiet",
- "-binary",
- "-tagOut!",
- jpegname,
- "-JpgFromRaw",
- filename,
- ]
- )
- self.jpegname = jpegname
- rotate_preview(jpegname, self.exif_tag)
- except FileNotFoundError:
- pass
+ if not have_thumbnail.pop(self.thumbname, False):
+ if not filename.lower().endswith((".cr2", ".cr3", ".rw2")):
+ im = rotate_image(im, self.exif_tag)
+
+ im.thumbnail((self.size * 4, self.size * 2))
+ im = im.convert("RGB")
+ im.save(self.thumbname, "JPEG")
+
+ if filename.lower().endswith((".cr2", ".cr3", ".rw2")):
+ try:
+ jpegname = f".thumbnails/{thumb_filename}.p.jpg"
+ subprocess.run(
+ [
+ "exiftool",
+ "-quiet",
+ "-binary",
+ "-tagOut!",
+ jpegname,
+ "-PreviewImage",
+ filename,
+ ]
+ )
+ # JpgFromRaw tends to have higher resolution, so overwrite PreviewImage if it is present
+ subprocess.run(
+ [
+ "exiftool",
+ "-quiet",
+ "-binary",
+ "-tagOut!",
+ jpegname,
+ "-JpgFromRaw",
+ filename,
+ ]
+ )
+ self.jpegname = jpegname
+ rotate_preview(jpegname, self.exif_tag)
+ have_thumbnail.pop(self.jpegname, None)
+ except FileNotFoundError:
+ pass
if args.with_detail_page and 0:
self.average_color = im.resize((1, 1)).getpixel((0, 0))
@@ -794,6 +797,10 @@ if __name__ == "__main__":
os.makedirs(".thumbnails", exist_ok=True)
+ rm_thumbnail = dict(
+ map(lambda k: (".thumbnails/" + k, 1), os.listdir(".thumbnails"))
+ )
+
if not args.cdn:
copy_files(f"{base_dir}/share")
@@ -876,6 +883,7 @@ if __name__ == "__main__":
with_gps=args.with_nominatim,
group_key_template=args.group,
file_key_template=args.group_files,
+ have_thumbnail=rm_thumbnail,
)
thumbnails.append(thumbnail)
@@ -923,6 +931,9 @@ if __name__ == "__main__":
+ [filename]
)
+ for rm_file in rm_thumbnail.keys():
+ os.remove(rm_file)
+
if args.sort == "time":
thumbnails = list(
sorted(thumbnails, key=lambda t: t.exif_dt, reverse=args.reverse)