From ebc416b39db46804c43adef55632218defb570d8 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 22 Jan 2022 01:37:56 +0200 Subject: [PATCH] dffssd --- files/helpers/images.py | 5 +++-- files/routes/comments.py | 8 ++++---- files/routes/posts.py | 8 ++++---- files/routes/settings.py | 8 ++++---- files/routes/static.py | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/files/helpers/images.py b/files/helpers/images.py index 990c2872b3..ff5f9e4b93 100644 --- a/files/helpers/images.py +++ b/files/helpers/images.py @@ -4,9 +4,10 @@ import time def process_image(file=None, filename=None, resize=0): - i = IImage.open(file) if not filename: filename = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp' + i = IImage.open(file) + if resize: size = resize, resize frames = ImageSequence.Iterator(i) @@ -24,7 +25,7 @@ def process_image(file=None, filename=None, resize=0): om.save(filename, format="WEBP", save_all=True, append_images=list(frames), loop=0, method=6, allow_mixed=True) elif i.format.lower() != "webp": if i.format.lower() == "gif": - i.save(filename) + file.save(filename) gifwebp(input_image=filename, output_image=filename, option="-mixed -metadata none -f 100 -mt -m 6") else: i.save(filename, format="WEBP", method=6) diff --git a/files/routes/comments.py b/files/routes/comments.py index d77cdea898..99a036a320 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -174,14 +174,14 @@ def api_comment(v): if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": file=request.files["file"] if file.content_type.startswith('image/'): - body += f"\n\n![]({process_image(file.stream)})" + body += f"\n\n![]({process_image(file)})" if v.admin_level == 3: if parent_post.id == 37696: filename = 'files/assets/images/Drama/sidebar/' + str(len(listdir('files/assets/images/Drama/sidebar'))+1) + '.webp' - text = process_image(file.stream, filename, 400) + text = process_image(file, filename, 400) elif parent_post.id == 37697: filename = 'files/assets/images/Drama/sidebar/' + str(len(listdir('files/assets/images/Drama/banners'))+1) + '.webp' - process_image(file.stream, filename) + process_image(file, filename) elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: @@ -639,7 +639,7 @@ def edit_comment(cid, v): if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": file=request.files["file"] if file.content_type.startswith('image/'): - body += f"\n\n![]({process_image(file.stream)})" + body += f"\n\n![]({process_image(file)})" elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: diff --git a/files/routes/posts.py b/files/routes/posts.py index 23a87efe83..6ebf90a5b2 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -419,7 +419,7 @@ def edit_post(pid, v): if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": file=request.files["file"] if file.content_type.startswith('image/'): - body += f"\n\n![]({process_image(file.stream)})" + body += f"\n\n![]({process_image(file)})" elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: @@ -848,7 +848,7 @@ def submit_post(v): if request.files.get("file2") and request.headers.get("cf-ipcountry") != "T1": file=request.files["file2"] if file.content_type.startswith('image/'): - body += f"\n\n![]({process_image(file.stream)})" + body += f"\n\n![]({process_image(file)})" elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: @@ -935,8 +935,8 @@ def submit_post(v): file = request.files['file'] if file.content_type.startswith('image/'): - new_post.url = process_image(file.stream) - new_post.thumburl = process_image(file.stream, resize=100) + new_post.url = process_image(file) + new_post.thumburl = process_image(file, resize=100) elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: diff --git a/files/routes/settings.py b/files/routes/settings.py index 6983290a90..04ac3f6b4c 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -255,7 +255,7 @@ def settings_profile_post(v): if request.files.get('file'): file = request.files['file'] if file.content_type.startswith('image/'): - bio += f"\n\n![]({process_image(file.stream)})" + bio += f"\n\n![]({process_image(file)})" elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: @@ -621,11 +621,11 @@ def settings_images_profile(v): file = request.files["profile"] - highres = process_image(file.stream) + highres = process_image(file) if not highres: abort(400) - imageurl = process_image(file.stream, resize=100) + imageurl = process_image(file, resize=100) if not imageurl: abort(400) @@ -652,7 +652,7 @@ def settings_images_banner(v): file = request.files["banner"] - bannerurl = process_image(file.stream) + bannerurl = process_image(file) if bannerurl: if v.bannerurl and '/images/' in v.bannerurl : os.remove('/images/' + v.bannerurl.split('/images/')[1]) diff --git a/files/routes/static.py b/files/routes/static.py index c50e022b09..879a1a7f80 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -271,7 +271,7 @@ def submit_contact(v): if request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": file=request.files["file"] if file.content_type.startswith('image/'): - body_html += f'' + body_html += f'' elif file.content_type.startswith('video/'): file.save("video.mp4") with open("video.mp4", 'rb') as f: