From 0d2e1fa18415605c091af15a9e97792e71f61a8f Mon Sep 17 00:00:00 2001 From: laggykiller Date: Sat, 20 Apr 2024 14:34:45 +0800 Subject: [PATCH] bg_color specified as rrggbbaa instead of rrggbb, allow setting bg_color with alpha!=0 --- src/sticker_convert/converter.py | 4 ++-- .../windows/advanced_compression_window.py | 9 +++++++-- src/sticker_convert/resources/help.json | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/sticker_convert/converter.py b/src/sticker_convert/converter.py index a498cee..c851082 100755 --- a/src/sticker_convert/converter.py +++ b/src/sticker_convert/converter.py @@ -186,8 +186,8 @@ def __init__( self.bg_color: Optional[Tuple[int, int, int, int]] = None if self.opt_comp.bg_color: - r, g, b = bytes.fromhex(self.opt_comp.bg_color) - self.bg_color = (r, g, b, 0) + r, g, b, a = bytes.fromhex(self.opt_comp.bg_color) + self.bg_color = (r, g, b, a) self.tmp_f: BytesIO = BytesIO() self.result: Optional[bytes] = None diff --git a/src/sticker_convert/gui_components/windows/advanced_compression_window.py b/src/sticker_convert/gui_components/windows/advanced_compression_window.py index 4d36564..d999c97 100644 --- a/src/sticker_convert/gui_components/windows/advanced_compression_window.py +++ b/src/sticker_convert/gui_components/windows/advanced_compression_window.py @@ -580,9 +580,14 @@ def cb_disable_fake_vid(self, *_: Any) -> None: self.fake_vid_cbox.config(state=state) def cb_bg_color(self, *_: Any) -> None: - color = colorchooser.askcolor(title="Choose color")[1] + color_init = self.gui.bg_color_var.get()[:6] + color = colorchooser.askcolor( + title="Choose color", + initialcolor=color_init, + parent=self, + )[1] if color: - self.gui.bg_color_var.set(color.replace("#", "")) + self.gui.bg_color_var.set(color.replace("#", "") + "00") self.lift() self.attributes("-topmost", True) # type: ignore self.attributes("-topmost", False) # type: ignore diff --git a/src/sticker_convert/resources/help.json b/src/sticker_convert/resources/help.json index 000b58a..ee86f89 100644 --- a/src/sticker_convert/resources/help.json +++ b/src/sticker_convert/resources/help.json @@ -40,7 +40,7 @@ "duration_min": "Set minimum output duration in miliseconds.", "duration_max": "Set maximum output duration in miliseconds.", "padding_percent": "Set percentage of space used as padding.", - "bg_color": "Set custom background color.\nExample: 00ff00 for green.\nIf this is not set, background color would be auto set to black if image is bright, or white if image is dark.\nNote: The color should not be visible if output format supports transparency.", + "bg_color": "Set custom background color in rrggbbaa format.\nExample: 00ff0000 for green with alpha 0.\nIf this is not set, background color would be auto set to black if image is bright, or white if image is dark.\nNote: The color should not be visible if output format supports transparency.", "size": "Set maximum file size in bytes for video and image.", "vid_size_max": "Set maximum file size limit for animated stickers.", "img_size_max": "Set maximum file size limit for static stickers.",