czxcxz
This commit is contained in:
parent
57a429881c
commit
31ab123613
2 changed files with 12 additions and 8 deletions
|
@ -5,9 +5,11 @@ import time
|
||||||
def process_image(file=None, filename=None, resize=0):
|
def process_image(file=None, filename=None, resize=0):
|
||||||
|
|
||||||
if not filename: filename = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
if not filename: filename = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||||
file.save(filename)
|
|
||||||
|
|
||||||
|
if file:
|
||||||
|
file.save(filename)
|
||||||
i = IImage.open(file)
|
i = IImage.open(file)
|
||||||
|
else: i = IImage.open(filename)
|
||||||
|
|
||||||
if resize:
|
if resize:
|
||||||
size = resize, resize
|
size = resize, resize
|
||||||
|
|
|
@ -613,9 +613,8 @@ def thumbnail_thread(pid):
|
||||||
if image_req.headers.get("Content-Type","").startswith("image/svg"):
|
if image_req.headers.get("Content-Type","").startswith("image/svg"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
image = BytesIO(image_req.content)
|
image = PILimage.open(BytesIO(image_req.content))
|
||||||
image2 = PILimage.open(image)
|
if image.width < 30 or image.height < 30:
|
||||||
if image2.width < 30 or image2.height < 30:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
break
|
break
|
||||||
|
@ -628,7 +627,6 @@ def thumbnail_thread(pid):
|
||||||
|
|
||||||
elif x.headers.get("Content-Type","").startswith("image/"):
|
elif x.headers.get("Content-Type","").startswith("image/"):
|
||||||
image_req=x
|
image_req=x
|
||||||
image = BytesIO(x.content)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
db.close()
|
db.close()
|
||||||
|
@ -636,7 +634,11 @@ def thumbnail_thread(pid):
|
||||||
|
|
||||||
name = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
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.add(post)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.close()
|
db.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue