Gif Update
We going to Fazbears Pizza with this one
This commit is contained in:
parent
def7e1845e
commit
22ecf59c62
29
app.py
29
app.py
@ -1,6 +1,7 @@
|
||||
import datetime
|
||||
import hashlib
|
||||
import os
|
||||
# import imageio
|
||||
from PIL import Image
|
||||
|
||||
from flask import Flask, render_template, redirect, url_for, request, jsonify
|
||||
@ -333,6 +334,7 @@ def edit_habit():
|
||||
errors={}
|
||||
)
|
||||
|
||||
|
||||
@app.route('/edit-habit', methods=['POST'])
|
||||
@login_required
|
||||
def edit_habit_change():
|
||||
@ -417,6 +419,7 @@ def edit_habit_change():
|
||||
# Back to index
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
@app.route('/check_password', methods=['POST'])
|
||||
@login_required
|
||||
def check_password():
|
||||
@ -466,6 +469,11 @@ def save_profile_image(image_file):
|
||||
# Get the filename from the image path saved in the user
|
||||
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
|
||||
image = Image.open(image_file)
|
||||
|
||||
@ -488,8 +496,18 @@ def save_profile_image(image_file):
|
||||
image = image.resize((256, 256))
|
||||
|
||||
# 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)
|
||||
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'])
|
||||
@ -501,13 +519,7 @@ def upload_profile_image():
|
||||
save_profile_image(file)
|
||||
|
||||
# Back to profile
|
||||
return render_template(
|
||||
"profile.html",
|
||||
name=current_user.name,
|
||||
email=current_user.email,
|
||||
profile_image_url=current_user.profile_image,
|
||||
errors={}
|
||||
)
|
||||
return redirect(url_for('profile'))
|
||||
|
||||
|
||||
@app.route('/check', methods=['POST'])
|
||||
@ -623,6 +635,7 @@ def users():
|
||||
errors={},
|
||||
)
|
||||
|
||||
|
||||
@app.route('/users', methods=['POST'])
|
||||
@login_required
|
||||
def add_user():
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user