resize image on client

This commit is contained in:
waltem01 2024-02-16 07:11:50 +01:00
parent bc37cb3c67
commit c4e3d04043

View File

@ -49,15 +49,12 @@ def display_image():
# receive client data # receive client data
data = request.form data = request.form
# try unpacking image width and height
width = int(data.get('w'))
height = int(data.get('h'))
# try unpacking x,y coordinates # try unpacking x,y coordinates
x_coord = int(data.get('x')) x_coord = int(data.get('x'))
y_coord = int(data.get('y')) y_coord = int(data.get('y'))
# call matrix method with data # call matrix method with data
matrix.display_image(x_coord, y_coord, width, height) matrix.display_image(x_coord, y_coord)
except Exception as e: except Exception as e:
# error handling # error handling
print(e) print(e)
@ -295,9 +292,8 @@ class Matrix(SampleBase):
self.image = Image.open(requests.get(url, stream=True).raw) self.image = Image.open(requests.get(url, stream=True).raw)
# display image at position with dimensions in current color # display image at position with dimensions in current color
def display_image(self, x: int, y: int, w: Optional[int] = None, h: Optional[int] = None): def display_image(self, x: int, y: int):
# resize image to specified or max size if self.image is None: return
self.image.resize((w or self.matrix.width, h or self.matrix.height), Image.ANTIALIAS)
# set image at position # set image at position
self.canvas.SetImage(self.image, x, y) self.canvas.SetImage(self.image, x, y)