3

I am using the following code:

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)

based on: How do I read image data from a URL in Python?

Now I need to base64 encode it for posting to Google Cloud Vision API. How to do that?

Or does the Google Cloud vision API work with image urls?

Community
  • 1
  • 1
ssk
  • 9,045
  • 26
  • 96
  • 169

1 Answers1

3

Assuming there's no need to parse the image, just grab it and encode it:

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
bhavin jalodara
  • 1,470
  • 9
  • 12
miken32
  • 42,008
  • 16
  • 111
  • 154