如何在Python 2.7上从图像url(jpeg)读取字节并在base64中编码?
我正在使用以下代码:如何在Python 2.7上从图像url(jpeg)读取字节并在base64中编码?,python,google-cloud-vision,Python,Google Cloud Vision,我正在使用以下代码: import urllib, cStringIO from PIL import Image url='https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' file = cStringIO.StringIO(urllib.urlopen(url).read()) img = Image.open(file) 基于: 现在我需要对它进行base64编码,以
import urllib, cStringIO
from PIL import Image
url='https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
file = cStringIO.StringIO(urllib.urlopen(url).read())
img = Image.open(file)
基于:
现在我需要对它进行base64编码,以便发布到Google Cloud Vision API。怎么做
或者Google Cloud vision API是否可以处理图像URL?假设不需要解析图像,只需抓取图像并对其编码即可:
import urllib2
import base64
url = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
contents = urllib2.urlopen(url).read()
data = base64.b64encode(contents)
print data