From f672b9c4b587b01faeaec167354b89d55cd8255b Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Fri, 29 Mar 2024 14:13:08 +0100 Subject: [PATCH] Resize images on save --- api/requirements.txt | 8 ++++++++ api/trotamundos.py | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/api/requirements.txt b/api/requirements.txt index 5aad892..cc0ef16 100644 --- a/api/requirements.txt +++ b/api/requirements.txt @@ -1 +1,9 @@ +blinker==1.6.2 +click==8.1.6 Flask==2.3.2 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.3 +pillow==10.2.0 +Werkzeug==2.3.6 + diff --git a/api/trotamundos.py b/api/trotamundos.py index d34f5d1..c81e2e3 100644 --- a/api/trotamundos.py +++ b/api/trotamundos.py @@ -1,4 +1,5 @@ from flask import Flask, request, jsonify, render_template +from PIL import Image import base64 import io import imghdr @@ -96,6 +97,10 @@ def save_image(filename, data): filename = "data/images/" + secure_filename(filename) with open(filename, 'wb') as f: f.write(data) + + image = Image.open(filename) + resized = image.thumbnail((1920, 1920)) + image.save(filename, 'jpeg') return filename def get_extension(image_data):