def upload_avatar():
u = g.user
if 'photo' in request.files:
form = request.form
filename = str(uuid3(NAMESPACE_DNS, str(u.id) + u.username + str(time.time()))).replace('-','')
try:
x = int(form['x'])
y = int(form['y'])
w = int(form['nw'])
h = int(form['nh'])
img = Image.open(request.files['photo'])
format = img.format
croped_img = crop_img(img, x, y, w, h)
filename = save_avatar(croped_img, filename, format)
url_path = current_app.config['UPLOADED_PHOTOS_URL']
old_name = u.avatar.split(url_path)[1]
remove_avatar(old_name)
u.avatar = url_path + filename
u.save()
except Exception as e:
print(e)
flash('????????2Mb?????', 'error')
return redirect(url_for('user.setting_view'))
评论列表
文章目录