从网络链接(img_url)来读取加载图片(python3).

W1. request & PIL

import urllib.request
from PIL import Image

img_url = ''
image = Image.open(urllib.request.urlopen(url))
width, height = image.size

或:

from PIL import Image
import requests
from io import BytesIO

img_url = ''
response = requests.get(img_url)
img = Image.open(BytesIO(response.content))

W2. imageio 库

Github - Imageio

from imageio import imread

img_url = ''
img = imread(img_url)

3. 参考

[1] - How do I read image data from a URL in Python? - stackoverflow

Last modification:December 10th, 2019 at 01:46 pm