在Python中调整tiff图像的大小

2024-09-29 01:21:42 发布

您现在位置:Python中文网/ 问答频道 /正文

尝试使用以下方法调整图像大小(重量>100 MB):

>>> from PIL import Image
>>> image = Image.open(path_to_the_file)
>>> new_image = image.resize((200, 200))

和接收到值错误:平铺无法扩展到图像外部。在

原始图像的大小为

^{pr2}$

我在做缩略图、旋转等时也收到了同样的错误

我做错什么了?在

编辑: 使用ImageMagic检查图像:

$ identify file.tif
file.tif[0] TIFF 4922x3707 4922x3707+0+0 32-bit Grayscale Gray 31.23MB   0.000u 0:00.009
file.tif[1] TIFF 2461x1854 2461x1854+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
filetif[2] TIFF 1231x927 1231x927+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
file.tif[3] TIFF 616x464 616x464+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
file.tif[4] TIFF 308x232 308x232+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
file.tif[5] TIFF 154x116 154x116+0+0 32-bit Grayscale Gray 31.23MB 0.000u 0:00.000
identify: Unknown field with tag 33550 (0x830e) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
identify: Unknown field with tag 33922 (0x8482) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
identify: Unknown field with tag 34735 (0x87af) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.
identify: Unknown field with tag 34736 (0x87b0) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/881.

Tags: 图像fieldtagwithbitmbunknownfile
3条回答

尝试添加Image.ANTIALIAS参数:

new_image = image.resize((200, 200), Image.ANTIALIAS)

在我以前的一个项目中,这对我很有用。在

您应该安装pytho resize图像包。在

一个例子

from PIL import Image

from resizeimage import resizeimage


with open('acajeb-image.jpeg', 'r+b') as f:
    with Image.open(f) as image:
        cover = resizeimage.resize_cover(image, [200, 200])
        cover.save('test-image-cover.jpeg', image.format)

您可以使用安装程序包

^{pr2}$

问题可能在这里,从docs

Note that the bilinear and bicubic filters in the current version of PIL are not well-suited for large downsampling ratios (e.g. when creating thumbnails). You should use ANTIALIAS unless speed is much more important than quality.

在本例中,在代码处添加Image.ANTIALIAS

from PIL import Image
image = Image.open(path_to_the_file)
new_image = image.resize((200, 200) Image.ANTIALIAS)

现在就可以了。在

相关问题 更多 >