remotes/1693045480750635534/spooky-22
Aevann1 2022-01-22 02:41:42 +02:00
parent 46d0c901a7
commit f29362d73f
2 changed files with 12 additions and 8 deletions

View File

@ -5,9 +5,11 @@ import time
def process_image(file=None, filename=None, resize=0):
if not filename: filename = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
file.save(filename)
i = IImage.open(file)
if file:
file.save(filename)
i = IImage.open(file)
else: i = IImage.open(filename)
if resize:
size = resize, resize

View File

@ -613,11 +613,10 @@ def thumbnail_thread(pid):
if image_req.headers.get("Content-Type","").startswith("image/svg"):
continue
image = BytesIO(image_req.content)
image2 = PILimage.open(image)
if image2.width < 30 or image2.height < 30:
image = PILimage.open(BytesIO(image_req.content))
if image.width < 30 or image.height < 30:
continue
break
else:
@ -628,7 +627,6 @@ def thumbnail_thread(pid):
elif x.headers.get("Content-Type","").startswith("image/"):
image_req=x
image = BytesIO(x.content)
else:
db.close()
@ -636,7 +634,11 @@ def thumbnail_thread(pid):
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
post.thumburl = process_image(image, resize=100)
with open(name, "wb") as file:
for chunk in image_req.iter_content(1024):
file.write(chunk)
post.thumburl = process_image(filename=name, resize=True)
db.add(post)
db.commit()
db.close()