forked from MarseyWorld/MarseyWorld
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)
|
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)")
|
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:
|
params.append(filename)
|
||||||
if trim and len(list(Iterator(i))) == 1:
|
subprocess.run(params)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if resize:
|
if resize:
|
||||||
|
|
Loading…
Reference in New Issue