Skip to content

Commit

Permalink
Resize images on save
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloalba committed Mar 29, 2024
1 parent 53f98c2 commit f672b9c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions api/trotamundos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from flask import Flask, request, jsonify, render_template
from PIL import Image
import base64
import io
import imghdr
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f672b9c

Please sign in to comment.