From 5ef9e3eddbd7641b6989b0e20a81c9c7f9ac4cbd Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Mon, 5 Apr 2021 13:13:16 +0200 Subject: [PATCH] Make background of png images configurable (#200) --- lib/fmt/png.py | 8 ++++++-- share/help.txt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/fmt/png.py b/lib/fmt/png.py index 6f7f063..7ee663a 100644 --- a/lib/fmt/png.py +++ b/lib/fmt/png.py @@ -163,7 +163,7 @@ def _load_emojilib(): emojilib = {} for filename in glob.glob("share/emoji/*.png"): - character = os.path.basename(filename)[:-4] + character = os.path.basename(filename)[:-3] emojilib[character] = \ Image.open(filename).resize((CHAR_HEIGHT, CHAR_HEIGHT)) return emojilib @@ -183,7 +183,11 @@ def _gen_term(buf, graphemes, options=None): cols = max(len(x) for x in buf) rows = len(buf) - image = Image.new('RGB', (cols * CHAR_WIDTH, rows * CHAR_HEIGHT)) + bg_color = 0 + if "background" in options: + bg_color = _color_mapping(options["background"]) + + image = Image.new('RGB', (cols * CHAR_WIDTH, rows * CHAR_HEIGHT), color=bg_color) buf = buf[-ROWS:] diff --git a/share/help.txt b/share/help.txt index e756a5e..7159118 100644 --- a/share/help.txt +++ b/share/help.txt @@ -42,6 +42,7 @@ PNG options: p # add frame around the output t # transparency 150 transparency=... # transparency from 0 to 255 (255 = not transparent) + background=... # background color in form RRGGBB, e.g. 00aaaa Options can be combined: