mirror of
https://github.com/Fluffy-Bean/GameExpo23.git
synced 2025-05-22 02:54:52 +00:00
Fix gif pfp uploading
This commit is contained in:
parent
961759e40b
commit
193c7d9d07
1 changed files with 15 additions and 7 deletions
|
@ -42,7 +42,7 @@ def settings():
|
||||||
|
|
||||||
if "file" in request.files and request.files['file'].filename:
|
if "file" in request.files and request.files['file'].filename:
|
||||||
picture = request.files["file"]
|
picture = request.files["file"]
|
||||||
file_ext = picture.filename.split(".")[-1]
|
file_ext = picture.filename.split(".")[-1].lower()
|
||||||
file_name = f"{user.id}.{file_ext}"
|
file_name = f"{user.id}.{file_ext}"
|
||||||
|
|
||||||
if file_ext not in UPLOAD_EXTENSIONS:
|
if file_ext not in UPLOAD_EXTENSIONS:
|
||||||
|
@ -51,11 +51,14 @@ def settings():
|
||||||
error.append(f"Picture must be less than {UPLOAD_EXTENSIONS / 1000000}MB!")
|
error.append(f"Picture must be less than {UPLOAD_EXTENSIONS / 1000000}MB!")
|
||||||
|
|
||||||
image = Image.open(picture.stream)
|
image = Image.open(picture.stream)
|
||||||
image_x, image_y = image.size
|
|
||||||
image.thumbnail((
|
# Resizing gifs is more work than it's worth
|
||||||
min(image_x, UPLOAD_RESOLUTION),
|
if file_ext != "gif":
|
||||||
min(image_y, UPLOAD_RESOLUTION)
|
image_x, image_y = image.size
|
||||||
))
|
image.thumbnail((
|
||||||
|
min(image_x, UPLOAD_RESOLUTION),
|
||||||
|
min(image_y, UPLOAD_RESOLUTION)
|
||||||
|
))
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
for err in error:
|
for err in error:
|
||||||
|
@ -66,7 +69,12 @@ def settings():
|
||||||
os.remove(os.path.join(UPLOAD_DIR, user.picture))
|
os.remove(os.path.join(UPLOAD_DIR, user.picture))
|
||||||
|
|
||||||
user.picture = file_name
|
user.picture = file_name
|
||||||
image.save(os.path.join(UPLOAD_DIR, file_name))
|
|
||||||
|
if file_ext == "gif":
|
||||||
|
image.save(os.path.join(UPLOAD_DIR, file_name), save_all=True)
|
||||||
|
else:
|
||||||
|
image.save(os.path.join(UPLOAD_DIR, file_name))
|
||||||
|
|
||||||
image.close()
|
image.close()
|
||||||
|
|
||||||
if username:
|
if username:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue