forked from MarseyWorld/MarseyWorld
close image files after ur done
parent
eafa7b8e05
commit
3b16c8f3e3
|
@ -170,15 +170,18 @@ def process_image(filename=None, resize=0, trim=False, uploader=None, patron=Fal
|
|||
if resize == 400 and img in ('256.webp','585.webp'): continue
|
||||
img_path = f'{path}/{img}'
|
||||
if img_path == filename: continue
|
||||
img = Image.open(img_path)
|
||||
i_hash = str(imagehash.phash(img))
|
||||
|
||||
with Image.open(img_path) as i:
|
||||
i_hash = str(imagehash.phash(i))
|
||||
|
||||
if i_hash in hashes.keys():
|
||||
print(hashes[i_hash], flush=True)
|
||||
print(img_path, flush=True)
|
||||
else: hashes[i_hash] = img_path
|
||||
|
||||
i = Image.open(filename)
|
||||
i_hash = str(imagehash.phash(i))
|
||||
with Image.open(filename) as i:
|
||||
i_hash = str(imagehash.phash(i))
|
||||
|
||||
if i_hash in hashes.keys():
|
||||
os.remove(filename)
|
||||
abort(409, "Image already exists!")
|
||||
|
|
|
@ -242,10 +242,10 @@ if SITE not in ('pcmemes.net', 'watchpeopledie.tv'):
|
|||
highquality = f'/asset_submissions/hats/{name}'
|
||||
file.save(highquality)
|
||||
|
||||
i = Image.open(highquality)
|
||||
if i.width > 100 or i.height > 130:
|
||||
os.remove(highquality)
|
||||
return error("Images must be 100x130")
|
||||
with Image.open(highquality) as i:
|
||||
if i.width > 100 or i.height > 130:
|
||||
os.remove(highquality)
|
||||
return error("Images must be 100x130")
|
||||
|
||||
if len(list(Iterator(i))) > 1: price = 1000
|
||||
else: price = 500
|
||||
|
|
|
@ -16,7 +16,7 @@ from files.classes import *
|
|||
from flask import *
|
||||
from io import BytesIO
|
||||
from files.__main__ import app, limiter, cache, db_session
|
||||
from PIL import Image as PILimage
|
||||
from PIL import Image
|
||||
from .front import frontlist
|
||||
from urllib.parse import ParseResult, urlunparse, urlparse, quote, unquote
|
||||
from os import path
|
||||
|
@ -607,9 +607,9 @@ def thumbnail_thread(pid):
|
|||
if image_req.headers.get("Content-Type","").startswith("image/svg"):
|
||||
continue
|
||||
|
||||
image = PILimage.open(BytesIO(image_req.content))
|
||||
if image.width < 30 or image.height < 30:
|
||||
continue
|
||||
with Image.open(BytesIO(image_req.content)) as i:
|
||||
if i.width < 30 or i.height < 30:
|
||||
continue
|
||||
|
||||
break
|
||||
|
||||
|
@ -621,13 +621,13 @@ def thumbnail_thread(pid):
|
|||
|
||||
elif x.headers.get("Content-Type","").startswith("image/"):
|
||||
image_req=x
|
||||
image = PILimage.open(BytesIO(x.content))
|
||||
with Image.open(BytesIO(x.content)) as i:
|
||||
size = len(i.fp.read())
|
||||
|
||||
else:
|
||||
db.close()
|
||||
return
|
||||
|
||||
size = len(image.fp.read())
|
||||
if size > 8 * 1024 * 1024:
|
||||
db.close()
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue