-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageHandler.py
33 lines (22 loc) · 930 Bytes
/
ImageHandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import wget
from PIL import Image
import requests
import json
def getImage(url): # called from the Cuttie.registerProfile method
filename = wget.download(url) # downloads the image from URL
# opens image, resizes, renames, reformats, saves copy
img = Image.open(filename)
filename = 'resized-' + filename
size = 500, 400
img = img.resize(size, Image.ANTIALIAS)
img.save(filename, "BMP") # BEWARE OF THE IMAGE CACHE
return filename # returns the copy path
def MorePictures(segment):
APIs = {'doggies': {'URL': "https://dog.ceo/api/breeds/image/random",
'key': "message"},
'kitties': {'URL': "http://aws.random.cat//meow",
'key': "file"}}
r = requests.get(APIs[segment]['URL'])
filename = wget.download(r.json()[APIs[segment]['key']]) # downloads the image from URL
img = Image.open(filename)
img.show()