Gif Update

We going to Fazbears Pizza with this one
This commit is contained in:
Yapollon 2024-03-07 10:38:53 +01:00
parent def7e1845e
commit 22ecf59c62

29
app.py
View File

@ -1,6 +1,7 @@
import datetime import datetime
import hashlib import hashlib
import os import os
# import imageio
from PIL import Image from PIL import Image
from flask import Flask, render_template, redirect, url_for, request, jsonify from flask import Flask, render_template, redirect, url_for, request, jsonify
@ -333,6 +334,7 @@ def edit_habit():
errors={} errors={}
) )
@app.route('/edit-habit', methods=['POST']) @app.route('/edit-habit', methods=['POST'])
@login_required @login_required
def edit_habit_change(): def edit_habit_change():
@ -417,6 +419,7 @@ def edit_habit_change():
# Back to index # Back to index
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route('/check_password', methods=['POST']) @app.route('/check_password', methods=['POST'])
@login_required @login_required
def check_password(): def check_password():
@ -466,6 +469,11 @@ def save_profile_image(image_file):
# Get the filename from the image path saved in the user # Get the filename from the image path saved in the user
filename = os.path.basename(current_user.profile_image) filename = os.path.basename(current_user.profile_image)
# Check if the image is an animated gif
if file_extension == 'gif':
save_profile_animated(image_file, filename)
return
# Open the uploaded image # Open the uploaded image
image = Image.open(image_file) image = Image.open(image_file)
@ -488,8 +496,18 @@ def save_profile_image(image_file):
image = image.resize((256, 256)) image = image.resize((256, 256))
# Save the processed image # Save the processed image
image_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) image_path = os.path.join(app.config['UPLOAD_FOLDER'], filename.replace(".gif", ".jpg"))
image.save(image_path, 'JPEG', quality=100) image.save(image_path, 'JPEG', quality=100)
current_user.update_profile_image(image_path)
def save_profile_animated(image_file, filename):
# Save the GIF temporarily
filename = filename.replace(".jpg", ".gif")
gif_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
image_file.save(gif_path)
current_user.update_profile_image(gif_path)
@app.route('/upload', methods=['POST']) @app.route('/upload', methods=['POST'])
@ -501,13 +519,7 @@ def upload_profile_image():
save_profile_image(file) save_profile_image(file)
# Back to profile # Back to profile
return render_template( return redirect(url_for('profile'))
"profile.html",
name=current_user.name,
email=current_user.email,
profile_image_url=current_user.profile_image,
errors={}
)
@app.route('/check', methods=['POST']) @app.route('/check', methods=['POST'])
@ -623,6 +635,7 @@ def users():
errors={}, errors={},
) )
@app.route('/users', methods=['POST']) @app.route('/users', methods=['POST'])
@login_required @login_required
def add_user(): def add_user():