python - 在 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()
解决方案
尝试在元组中作为right_img.resize((400, 400))
. 也left_img.resize
应该改变。让我知道这是否有帮助。参考:文档
推荐阅读
- html - TD标签中的文本右对齐
- arrays - 按值排序多维关联数组 (SWIFT)
- sql - 为连接表中所有缺失的组合返回 0
- google-apps-script - 在 Google 的开发者控制台上创建的应用程序中如何创建 OAuth 凭据?
- oracle - 40735: 按下按钮时触发器引发未处理的异常 ORA-305500
- java - 无法连接到 oracle 数据库。它说“无法从数据源确定 jdbc url”
- laravel - 尝试在 GetStream 中向用户添加提要时出错
- java - java.lang.OutOfMemoryError 的含义:null
- go - 如何在 GO 中访问另一个文件
- android - 我收到此错误“任务':app:compileDebugJavaWithJavac'的执行失败。”