From 0831e751c35174aea8989f71271763c02d0110ae Mon Sep 17 00:00:00 2001 From: waltem01 Date: Fri, 16 Feb 2024 07:12:12 +0100 Subject: [PATCH] decode image from data url --- API/main.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/API/main.py b/API/main.py index 0c0e151..92b67ec 100755 --- a/API/main.py +++ b/API/main.py @@ -3,7 +3,8 @@ from deps.samplebase import SampleBase from rgbmatrix import graphics from typing import Optional from PIL import Image -import requests +import base64 +import io from flask import Flask, request, jsonify from flask_cors import CORS, cross_origin @@ -289,7 +290,9 @@ class Matrix(SampleBase): # set current image def set_image(self, url: str): - self.image = Image.open(requests.get(url, stream=True).raw) + _, data = url.split(',') + data = base64.b64decode(data) + self.image = Image.open(io.BytesIO(data)).convert('RGB') # display image at position with dimensions in current color def display_image(self, x: int, y: int):