From d5f18c06ece9bc6f24a9d19aabd4fe74732efd77 Mon Sep 17 00:00:00 2001 From: CyberArtemio <156206062+cyberartemio@users.noreply.github.com> Date: Wed, 3 Apr 2024 14:29:25 +0200 Subject: [PATCH] [core] changed icon rendering logic (maybe fix #14) --- README.md | 3 ++- wof.py | 26 ++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 92cf3d0..2504c98 100644 --- a/README.md +++ b/README.md @@ -97,4 +97,5 @@ If you want to contribute, you can fork the project and then open a pull request ## 🥇 Credits -- Wall of Flippers by K3YOMI ([Github](https://github.com/K3YOMI/Wall-of-Flippers)) \ No newline at end of file +- For Wall of Flipper: `Wall of Flippers` by K3YOMI ([Github](https://github.com/K3YOMI/Wall-of-Flippers)) +- For icon rendering: `InternetConnectionPlugin` by NeonLightning ([Github](https://github.com/NeonLightning/pwny/blob/main/internet-conection.py)) \ No newline at end of file diff --git a/wof.py b/wof.py index 8671a4b..9ab2c3c 100644 --- a/wof.py +++ b/wof.py @@ -2,7 +2,7 @@ import os import json import time -from PIL import Image +from PIL import Image, ImageOps import pwnagotchi.plugins as plugins from pwnagotchi.ui.components import LabeledValue, Widget from pwnagotchi.ui.view import BLACK @@ -407,7 +407,7 @@ def on_ui_setup(self, ui): text_font = fonts.Small)) if self.__icon: - ui.add_element('wof_logo', Frame(path = f'{self.__assets_path}/flipper.png', xy = self.__position, reverse = self.__reverse)) + ui.add_element('wof_logo', FlipperIcon(path = f'{self.__assets_path}/flipper.png', xy = self.__position, reverse = self.__reverse)) def on_ui_update(self, ui): flippers = self.__wof_bridge.get_update() @@ -456,16 +456,22 @@ def on_webhook(self, path, request): abort(404) abort(404) -# Credits: https://github.com/roodriiigooo/PWNAGOTCHI-CUSTOM-FACES-MOD -class Frame(Widget): - def __init__(self, path, xy, alpha = 0, reverse = False): +# Credits: https://github.com/NeonLightning/pwny/blob/main/internet-conection.py +class FlipperIcon(Widget): + def __init__(self, path, xy, reverse = False): super().__init__(xy) self.image = Image.open(path).resize((15, 15)).convert('RGBA') - self.alpha = alpha self.reverse = reverse def draw(self, canvas, drawer): - r, g, b, a = self.image.split() - alpha = Image.new('L', self.image.size, self.alpha) - canvas.paste(self.image, self.xy, mask = alpha) - canvas.paste(255 if self.reverse else 0, self.xy, mask = a) \ No newline at end of file + pixels = self.image.load() + for y in range(self.image.size[1]): + for x in range(self.image.size[0]): + if pixels[x,y][3] == 0: + pixels[x,y] = (255, 255, 255, 255) + elif pixels[x,y][3] < 255: + pixels[x,y] = (0, 0, 0, 255) + + image = ImageOps.colorize(self.image.convert('L'), black = "white", white = "black") if self.reverse else self.image + image = image.convert('1') + canvas.paste(image, self.xy) \ No newline at end of file