Skip to content

Instantly share code, notes, and snippets.

@s-wool
Created February 21, 2016 05:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save s-wool/e1af395a051627e81a2b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import requests
import json
headers = {
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': 'xxx',
}
params = {
'width': '120',
'height': '120',
'smartCropping': 'true',
}
input = open('/path/to/input.jpg', 'rb')
body = input.read()
input.close()
try:
res = requests.post("https://api.projectoxford.ai/vision/v1/thumbnails",
verify=True,
headers=headers,
params=params,
data=body)
print(res.status_code)
if res.status_code == requests.codes.ok:
f = open('/path/to/image.jpg', 'wb')
f.write(res.content)
f.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment