使用Python从url处理img
如何处理url中的图像? 我正在从特定的url打开图像并尝试处理它使用Python从url处理img,python,python-2.7,python-imaging-library,Python,Python 2.7,Python Imaging Library,如何处理url中的图像? 我正在从特定的url打开图像并尝试处理它 import PIL from PIL import ImageFont from PIL import Image from PIL import ImageDraw url="https://www.google.com/images/srpr/logo11w.png" img = Image.open(url) ----- ---Lines of code--
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
url="https://www.google.com/images/srpr/logo11w.png"
img = Image.open(url)
-----
---Lines of code--
-----
这给了我一个错误:IOError:[Errno 22]无效模式('rb')或文件名
我在这里干什么呢?比这更复杂一点。首先,您需要使用
urllib
下载数据。然后将该数据存储在StringIO
对象中。最后,从PIL中的该对象打开:
import urllib
import StringIO
imgdata = urllib.urlopen(url).read()
img = Image.open(StringIO.StringIO(imgdata))