我想通过选择图像的一个子区域来裁剪图像以变成一个新的图像文件。
根据我在 PIL 文档中看到的内容,我试图在两种方法之间做出决定。
对于这两种方法:
# assume I already have a PIL-opened image called original_image
# assume I have a crop_box tuple for the area to crop, e.g. (0, 0, 100, 100)
方法
直接裁剪原始图像,然后将返回的裁剪区域转换为新文件。似乎我放弃了有关原始图像的所有模式数据/其他元数据,然后必须重新加载?
cropped_image = original_image.crop(crop_box) # process cropped version as needed
做一个
image.transform()
我选择一个子区域# assume I have an output size of (100, 100) cropped_image = original_image.transform(size, Image.EXTENT, crop_box) # process cropped version as needed
就速度、数据保存或我遗漏的另一个重要因素而言,一种方法是否优于另一种方法?