Skip to content

Commit

Permalink
[core] changed icon rendering logic (maybe fix #14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberartemio committed Apr 4, 2024
1 parent 36b9fc7 commit d5f18c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
- 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))
26 changes: 16 additions & 10 deletions wof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
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)

0 comments on commit d5f18c0

Please sign in to comment.