使用 Pillow Python 调整图像大小

The*_*ard 2 python python-imaging-library pillow

现在我正在尝试调整一些 .jpg 文件的大小,我的脚本如下:

from PIL import Image

def main( ): #{

    filename = "amonstercallsmoviestill.jpg"

    image = Image.open(filename)
    size = width, height = image.size

    image.thumbnail((1600,900))

    image.show()

    del image
#}

if (__name__ == "__main__" ): #{

    main()
#}
Run Code Online (Sandbox Code Playgroud)

我正在尝试将 amonstercallsmoviestill.jpg 的大小调整为 (1600,900),但它似乎不起作用。

我已经尝试过 (300,300) 并且它们可以工作,但是每当尝试使用 (1600,900) 进行缩略图时,它似乎都不起作用。

谢谢!

Mar*_*som 6

thumbnail降低了的图像的大小。要使它更大,请resize改用。

image = image.resize((1600, 900), PIL.Image.LANCZOS)
Run Code Online (Sandbox Code Playgroud)