我不确定为什么 Image.thumbnail 会受到如此抨击。在我正在使用它的当前版本中,它只不过是找出所需的大小并调整图像的大小。只要您使用正确的重采样过滤器并首先转换为 RGB(如 bobince 所说),缩略图不应与调整大小有任何不同。
这是缩略图方法的实际来源:
def thumbnail(self, size, resample=NEAREST):
# preserve aspect ratio
x, y = self.size
if x > size[0]: y = max(y * size[0] / x, 1); x = size[0]
if y > size[1]: x = max(x * size[1] / y, 1); y = size[1]
size = x, y
if size == self.size:
return
self.draft(None, size)
self.load()
try:
im = self.resize(size, resample)
except ValueError:
if resample != ANTIALIAS:
raise
im = self.resize(size, NEAREST) # fallback
self.im = im.im
self.mode = im.mode
self.size = size
self.readonly = 0