decode image from data url

This commit is contained in:
waltem01 2024-02-16 07:12:12 +01:00
parent c4e3d04043
commit 0831e751c3

View File

@ -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):