Why does making a thumbnail change the source object's size?

thumbnail scales a picture proportionally within two limits and changes the image object in place.

Pixel experiment and interpretation

Copy an 8-by-4 master before making a preview bounded by 3 by 3. Later crops retain the master resolution, and the preview may leave space in the box.

from PIL import Image

im=Image.new('L',(8,4))
preview=im.copy()
preview.thumbnail((3,3))
(im.size,preview.size)

Result ((8, 4), (3, 2))

中文

缩略图生成后为何原图尺寸也变了?

thumbnail 在给定宽高上限内按比例缩小,直接修改图像对象。

像素实验与适用边界

给 8×4 的原图留一份副本再做 3×3 预览。后续裁剪仍可用原始分辨率;不能假设预览恰好填满方框。

from PIL import Image

im=Image.new('L',(8,4))
preview=im.copy()
preview.thumbnail((3,3))
(im.size,preview.size)

结果 ((8, 4), (3, 2))

References / 参考来源

Keep reading / 继续阅读