import os from PIL import Image p = "/home/maxi/Projekt/wtc.waiswuaschd.de/app/static/img/chapters/chapter_1.png" im = Image.open(p) # Downscale with high quality Lanczos filter to 450x450 im = im.resize((450, 450), Image.Resampling.LANCZOS) im.save(p, "PNG", optimize=True) print("Resized chapter_1.png to 450x450")