forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2022-01-22 01:37:56 +02:00
parent ad75fbc874
commit ebc416b39d
5 changed files with 16 additions and 15 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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:

View File

@ -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])

View File

@ -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'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="in-comment-image" src="{process_image(file.stream)}" loading="lazy">'
body_html += f'<img data-bs-target="#expandImageModal" data-bs-toggle="modal" onclick="expandDesktopImage(this.src)" class="in-comment-image" src="{process_image(file)}" loading="lazy">'
elif file.content_type.startswith('video/'):
file.save("video.mp4")
with open("video.mp4", 'rb') as f: