diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2024-05-15 20:18:51 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2024-05-15 20:18:51 +0200 |
commit | cc9e8249c77fcdbbb80ec9a18e6eb2e4d1fb4527 (patch) | |
tree | 1de70f8eefd4a07922bd9061f27e36eb758c55d1 /bin | |
parent | ac25ff14a613de10ada9d81d3cd5ff2eda39e931 (diff) |
Extract preview images from CR2 files and use those for full view
CR2 files are still offered for download
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/pyggle | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -166,7 +166,9 @@ class ImageHTML: else: self.subject_distance = f"""<span class="subject-distance">∞</span>""" - def to_thumbnail_html(self, index, filename, thumbname, with_detail_page=False): + def to_thumbnail_html( + self, index, filename, thumbname, with_detail_page=False, jpegfile=None + ): if with_detail_page: self.focus = f"""<a href="{filename}.html">{self.focus}</a>""" @@ -180,7 +182,7 @@ class ImageHTML: exif_html = """ <span class="sep">•</span> """.join(filter(bool, exif_lines)) buf = """<div class="image-container">\n""" - buf += f"""<a href="{filename}" class="glightbox" data-gallery="gallery1" data-description=".gdesc{index}">""" + buf += f"""<a href="{jpegfile or filename}" class="glightbox" data-gallery="gallery1" data-description=".gdesc{index}">""" buf += f"""<img src="{thumbname}" alt="{linktext}" />""" buf += "</a>" buf += "</div>" @@ -256,6 +258,7 @@ class Thumbnail: file_key_template=None, ): self.filename = filename + self.jpegname = None self.size = size self.exif_dt = None self.gps = None @@ -291,6 +294,24 @@ class Thumbnail: im = im.convert("RGB") im.save(self.thumbname, "JPEG") + if filename.lower().endswith(".cr2"): + try: + jpegname = f".thumbnails/{thumb_filename}.p.jpg" + subprocess.run( + [ + "exiftool", + "-quiet", + "-binary", + "-tagOut!", + jpegname, + "-PreviewImage", + filename, + ] + ) + self.jpegname = jpegname + except FileNotFoundError: + pass + if args.with_detail_page and 0: self.average_color = im.resize((1, 1)).getpixel((0, 0)) self.luminance = im.convert("L").getpixel((0, 0)) @@ -531,7 +552,11 @@ class Thumbnail: def to_html(self, index, with_detail_page=False): return self.html.to_thumbnail_html( - index, self.filename, self.thumbname, with_detail_page + index, + self.filename, + self.thumbname, + with_detail_page, + jpegfile=self.jpegname, ) def to_detail_html(self, html_prefix, html_postfix): |