From 415f2f9987f72a8d9fed4c82d1e1fc789b25ee9f Mon Sep 17 00:00:00 2001 From: CiscoTheWolf Date: Thu, 18 May 2023 11:30:46 +0200 Subject: [PATCH] utilise a custom rgba to rgb image type converter. One that is aware of brightness(a) --- rpi/roy-test.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/rpi/roy-test.py b/rpi/roy-test.py index 0ed23e0..cfa23ca 100644 --- a/rpi/roy-test.py +++ b/rpi/roy-test.py @@ -15,15 +15,35 @@ matrix = RGBMatrix(options = options) # Load image and make sure it fits our screen. +def pure_pil_alpha_to_color_v2(image, color=(0, 0, 0)): + """Alpha composite an RGBA Image with a specified color. + + Simpler, faster version than the solutions above. + + Source: http://stackoverflow.com/a/9459208/284318 + + Keyword Arguments: + image -- PIL RGBA Image object + color -- Tuple r, g, b (default 255, 255, 255) + + """ + image.load() # needed for split() + background = Image.new('RGB', image.size, color) + background.paste(image, mask=image.split()[3]) # 3 is the alpha channel + return background + image = Image.open("../testImg.bmp") -image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS) +RGBImage = pure_pil_alpha_to_color_v2(image.thumbnail((128,62), Image.ANTIALIAS)) + + + # offscreen canvas that can be written to which can then be set to the matrix async offscreen_canvas = matrix.CreateFrameCanvas() offscreen_canvas.brightness = 50 offscreen__text_canvas = matrix.CreateFrameCanvas() offscreen__text_canvas.brightness = 50 -offscreen__text_canvas.SetImage(image.convert('RGB')) +offscreen__text_canvas.SetImage(RGBImage) def updateScreen():