From 0e4badb22d7666d0db3737cb3a910437b5b0bf52 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 25 May 2021 21:39:47 +0200 Subject: detail page: use average image color for background just a test. may be reverted. --- bin/pyggle | 23 ++++++++++++++++++++--- share/html_detail_start | 26 +------------------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/bin/pyggle b/bin/pyggle index 58319f1..3b2e0ff 100755 --- a/bin/pyggle +++ b/bin/pyggle @@ -188,7 +188,12 @@ class Thumbnail: im = rotate_image(im, self.exif_tag) im.thumbnail((self.size * 2, self.size * 2)) - im.convert("RGB").save(self.thumbname, "JPEG") + im = im.convert("RGB") + im.save(self.thumbname, "JPEG") + + if args.with_detail_page: + self.average_color = im.resize((1, 1)).getpixel((0, 0)) + self.luminance = im.convert("L").getpixel((0, 0)) self.html = ImageHTML() @@ -354,8 +359,20 @@ class Thumbnail: def to_detail_html(self, html_prefix, html_postfix): with open(f"{self.filename}.html", "w") as f: - f.write(html_prefix.replace("", self.filename)) - f.write(self.html.to_detail_html(self.filename)) + prefix = html_prefix.replace("", self.filename) + r, g, b = self.average_color + prefix = prefix.replace( + "", f"""""" + ) + prefix = prefix.replace( + "", f"""""" + ) + if self.luminance >= 127: + prefix = prefix.replace("", "light") + else: + prefix = prefix.replace("", "dark") + f.write(prefix) + f.write(self.html.to_detail_html(self.filename, self.exif_tag)) f.write(html_postfix) diff --git a/share/html_detail_start b/share/html_detail_start index 2cd32ec..de0b12b 100644 --- a/share/html_detail_start +++ b/share/html_detail_start @@ -5,30 +5,6 @@ - - + -- cgit v1.2.3