summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2024-05-26 09:31:00 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2024-05-26 09:31:00 +0200
commitb85a07ee83b366687aba3408c3076b29ca88b8e8 (patch)
tree7fe4529c2014c6c020ae123ebb90df2c048ec444
parent7304857570feecfc7d3d23bc26e6d1c1c3de90ab (diff)
use thumbnails in subdirectories if present
-rwxr-xr-xbin/pyggle98
1 files changed, 56 insertions, 42 deletions
diff --git a/bin/pyggle b/bin/pyggle
index 4487ce8..4b88749 100755
--- a/bin/pyggle
+++ b/bin/pyggle
@@ -314,48 +314,62 @@ class Thumbnail:
except FileNotFoundError:
pass
- thumb_filename = filename.replace("/", "-")
- self.thumbname = f".thumbnails/{thumb_filename}"
- 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
+ have_subthumb = False
+
+ if "/" in filename:
+ sub_dirname, sub_filename = filename.rsplit("/", 1)
+ sub_thumbname = sub_filename
+ if not sub_thumbname.lower().endswith((".jpeg", ".jpg")):
+ sub_thumbname += ".jpg"
+ if os.path.exists(f"{sub_dirname}/.thumbnails/{sub_thumbname}"):
+ self.thumbname = f"{sub_dirname}/.thumbnails/{sub_thumbname}"
+ have_subthumb = True
+ if os.path.exists(f"{sub_dirname}/.thumbnails/{sub_filename}.p.jpg"):
+ self.jpegname = f"{sub_dirname}/.thumbnails/{sub_filename}"
+
+ if not have_subthumb:
+ thumb_filename = filename.replace("/", "-")
+ self.thumbname = f".thumbnails/{thumb_filename}"
+ 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 args.with_detail_page and 0:
self.average_color = im.resize((1, 1)).getpixel((0, 0))