我正在创建调整图像大小的功能。图片上传并保存到webdav服务器后,但图片内容为空。
我从webdav下载图像,并检查了字节并返回 b'' 我已经调试了代码,这段代码没有任何回报。
img = Image.open(image_path) if img_obj is None else img_obj
format = img.format
img = img.resize((width, height), Image.ANTIALIAS)
with BytesIO() as content:
img.save(content, format)
thumb_io = content
return thumb_io
我希望输出与img.tobytes()相同,但实际输出为b'',而且无需调整函数大小就可以了。
@编辑 我是通过这种方式获得图片的:
download = requests.get('https://services/sample-img.jpg')
thumb_io = BytesIO(download.content)
img = Image.open(thumb_io) # Here BytesIO from img return b'' why?
...
resize func
答案 0 :(得分:0)
尝试:-
download = requests.get("Image_URL")
stream = io.BytesIO(download.content)
img = Image.open(stream)
img = img.resize((width, height))
img.save("new_file_name.ext")