use imagemagick in all cases
parent
3b16c8f3e3
commit
b9d998bdbe
|
@ -130,28 +130,13 @@ def process_image(filename=None, resize=0, trim=False, uploader=None, patron=Fal
|
|||
os.remove(filename)
|
||||
abort(413, f"Max image/audio size is {MAX_IMAGE_AUDIO_SIZE_MB} MB ({MAX_IMAGE_AUDIO_SIZE_MB_PATRON} MB for paypigs)")
|
||||
|
||||
i = Image.open(filename)
|
||||
with Image.open(filename) as i:
|
||||
params = ["convert", filename, "-coalesce"]
|
||||
if trim and len(list(Iterator(i))) == 1: params.append("-trim")
|
||||
if resize and i.width > resize: params.extend(["-resize", f"{resize}>"])
|
||||
|
||||
if resize and i.width > resize:
|
||||
if trim and len(list(Iterator(i))) == 1:
|
||||
subprocess.run(["convert", filename, "-coalesce", "-trim", "-resize", f"{resize}>", filename])
|
||||
else:
|
||||
try: subprocess.run(["convert", filename, "-coalesce", "-resize", f"{resize}>", filename])
|
||||
except: pass
|
||||
elif i.format.lower() != "webp":
|
||||
|
||||
exif = i.getexif()
|
||||
for k in exif.keys():
|
||||
if k != 0x0112:
|
||||
exif[k] = None
|
||||
del exif[k]
|
||||
i.info["exif"] = exif.tobytes()
|
||||
|
||||
if i.format.lower() == "gif":
|
||||
gifwebp(input_image=filename, output_image=filename, option="-mixed -metadata none -f 100 -mt -m 6")
|
||||
else:
|
||||
i = ImageOps.exif_transpose(i)
|
||||
i.save(filename, format="WEBP", method=6, quality=88)
|
||||
params.append(filename)
|
||||
subprocess.run(params)
|
||||
|
||||
|
||||
if resize:
|
||||
|
|
Loading…
Reference in New Issue