Python PIL:如何保存裁剪的图像?

bog*_*tan 5 python crop python-imaging-library

我有一个脚本,可以创建一个图像并将其裁剪掉.问题是,在我调用crop()方法后,它不会保存在磁盘上

crop = image.crop(x_offset, Y_offset, width, height).load()
return crop.save(image_path, format)
Run Code Online (Sandbox Code Playgroud)

voi*_*hos 9

您需要将参数传递.crop()给元组.并且不要使用.load()

box = (x_offset, Y_offset, width, height)
crop = image.crop(box)
return crop.save(image_path, format)
Run Code Online (Sandbox Code Playgroud)

这就是你所需要的.虽然,我不确定你为什么要返回保存操作的结果; 它返回None.