From b47edc5f0d15945044346791982cdd9fb4803845 Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 26 May 2021 13:07:33 +0200 Subject: [PATCH] Add dark mode --- bookwyrm/preview_images.py | 13 ++++++++++--- bookwyrm/settings.py | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 304250a2..9539edba 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -196,14 +196,21 @@ def generate_preview_image(texts={}, picture=None, rating=None, show_instance_la # Color - if BG_COLOR == "use_dominant_color": + if BG_COLOR in ["use_dominant_color_light", "use_dominant_color_dark"]: image_bg_color = "rgb(%s, %s, %s)" % dominant_color - # Lighten color + + # Adjust color image_bg_color_rgb = [x / 255.0 for x in ImageColor.getrgb(image_bg_color)] image_bg_color_hls = colorsys.rgb_to_hls(*image_bg_color_rgb) + + if BG_COLOR == "use_dominant_color_light": + lightness = max(0.9, image_bg_color_hls[1]) + else: + lightness = min(0.15, image_bg_color_hls[1]) + image_bg_color_hls = ( image_bg_color_hls[0], - max(0.9, image_bg_color_hls[1]), + lightness, image_bg_color_hls[2], ) image_bg_color = tuple( diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index db15be46..ce5c4547 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -39,11 +39,12 @@ DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # Preview image -# Specify RGB tuple or RGB hex strings, or 'use_dominant_color' -PREVIEW_BG_COLOR = "use_dominant_color" +# Specify RGB tuple or RGB hex strings, +# or "use_dominant_color_light" / "use_dominant_color_dark" +PREVIEW_BG_COLOR = "use_dominant_color_dark" PREVIEW_IMG_WIDTH = 1200 PREVIEW_IMG_HEIGHT = 630 -PREVIEW_TEXT_COLOR = "#363636" +PREVIEW_TEXT_COLOR = "#FFF" PREVIEW_DEFAULT_COVER_COLOR = "#002549" # Quick-start development settings - unsuitable for production