diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index 7596d6cc..d253602a 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -155,6 +155,7 @@ ui.faces.upload = "(1__0)" ui.faces.upload1 = "(1__1)" ui.faces.upload2 = "(0__1)" ui.faces.png = false +ui.faces.scale = 1 ui.faces.position_x = 0 ui.faces.position_y = 34 diff --git a/pwnagotchi/ui/components.py b/pwnagotchi/ui/components.py index 8537cddf..d60d02e8 100644 --- a/pwnagotchi/ui/components.py +++ b/pwnagotchi/ui/components.py @@ -44,7 +44,7 @@ def draw(self, canvas, drawer): class Text(Widget): - def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0, png=False): + def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, max_length=0, png=False, scale=1): super().__init__(position, color) self.value = value self.font = font @@ -52,6 +52,7 @@ def __init__(self, value="", position=(0, 0), font=None, color=0, wrap=False, ma self.max_length = max_length self.wrapper = TextWrapper(width=self.max_length, replace_whitespace=False) if wrap else None self.png = png + self.scale = scale def draw(self, canvas, drawer): if self.value is not None: @@ -67,16 +68,30 @@ def draw(self, canvas, drawer): self.pixels = self.image.load() for y in range(self.image.size[1]): for x in range(self.image.size[0]): - if self.pixels[x,y][3] < 255: # check alpha - self.pixels[x,y] = (255, 255, 255, 255) + if self.pixels[x, y][3] < 255: + self.pixels[x, y] = (255, 255, 255, 255) if self.color == 255: - self._image = ImageOps.colorize(self.image.convert('L'), black = "white", white = "black") + self._image = ImageOps.colorize(self.image.convert('L'), black="white", white="black") else: self._image = self.image - self.image = self._image.convert('1') + if self.scale != 1: + width, height = self._image.size + new_width = int(width * self.scale) + new_height = int(height * self.scale) + scaled_image = Image.new('RGBA', (new_width, new_height)) + original_pixels = self._image.load() + scaled_pixels = scaled_image.load() + for y in range(new_height): + for x in range(new_width): + original_x = x // self.scale + original_y = y // self.scale + scaled_pixels[x, y] = original_pixels[original_x, original_y] + self.image = scaled_image + else: + self.image = self._image + self.image = self.image.convert('1') canvas.paste(self.image, self.xy) - class LabeledValue(Widget): def __init__(self, label, value="", position=(0, 0), label_font=None, text_font=None, color=0, label_spacing=5): super().__init__(position, color) diff --git a/pwnagotchi/ui/faces.py b/pwnagotchi/ui/faces.py index a81966c5..053fffdb 100644 --- a/pwnagotchi/ui/faces.py +++ b/pwnagotchi/ui/faces.py @@ -23,6 +23,7 @@ UPLOAD = '(1__0)' UPLOAD1 = '(1__1)' UPLOAD2 = '(0__1)' +SCALE = 1 PNG = False POSITION_X = 0 POSITION_Y = 40 diff --git a/pwnagotchi/ui/view.py b/pwnagotchi/ui/view.py index 0c5ad5da..290ac026 100644 --- a/pwnagotchi/ui/view.py +++ b/pwnagotchi/ui/view.py @@ -67,8 +67,11 @@ def __init__(self, config, impl, state=None): 'line2': Line(self._layout['line2'], color=BLACK), 'face': Text(value=faces.SLEEP, - position=(config['ui']['faces']['position_x'], config['ui']['faces']['position_y']), - color=BLACK, font=fonts.Huge, png=config['ui']['faces']['png']), + position=(config['ui']['faces']['position_x'], config['ui']['faces']['position_y']), + color=BLACK, font=fonts.Huge, + png=config['ui']['faces']['png'], + scale = config['ui']['faces'].get('scale', 1) + ), # 'friend_face': Text(value=None, position=self._layout['friend_face'], font=fonts.Bold, color=BLACK), 'friend_name': Text(value=None, position=self._layout['friend_face'], font=fonts.BoldSmall, color=BLACK),