首页 > 解决方案 > 在 PIL 中调整图像大小时不了解此 ValueError 的原因

问题描述

当我运行我的代码时,它给了我一个我以前从未见过的奇怪错误。这是错误:
ValueError: Unknown resampling filter (400). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Image.BICUBIC (3), Image.BOX (4) or Image.HAMMING (5)

这是我的代码:

import re, requests, io
import PIL, PIL.Image, PIL.ImageOps, PIL.ImageSequence

imgurl = 'https://image.shutterstock.com/image-photo/table-wooden-floor-natural-lanescape-260nw-1895905258.jpg'
download = requests.get(imgurl)

type(download.content)

right_img = PIL.Image.open(io.BytesIO(download.content))
right_img_resized =  right_img.resize(400, 400) # <-- HERE IT GIVES ME AN ERROR
right_img_developed = right_img_resized.transform((400, 300), PIL.Image.QUAD, data=(0, 0, 100, 300, 300, 400, 400, 0), reshape=PIL.Image.BILINEAR)

left_img_url = re.sub('FRB', 'FLB', imgurl)
left_img = PIL.Image.open(io.BytesIO(requests.get(left_img_url).content))

left_img_resized = left_img.resize(400, 400)
left_img_developed = left_img_resized.transform((400, 300), PIL.Image.QUAD, data=(0, 0, 100, 300, 300, 400, 400, 0), reshape=PIL.Image.BILINEAR)

red_img = PIL.ImageOps.colorize(right_img_developed, (0,0,0), (255, 0, 0))
cylan_img = PIL.ImageOps.colorize(left_img_developed, (0, 0, 0)), (0, 255, 255)

blend = PIL.Image.blend(red_img, cylan_img, 0.5)
brightness = PIL.ImageEnhance.Brightness(blend)
image_3d = brightness.enhance(1.75)
image_3d.show()

标签: pythonimagepython-imaging-library

解决方案


尝试在元组中作为right_img.resize((400, 400)). 也left_img.resize应该改变。让我知道这是否有帮助。参考:文档


推荐阅读