def get_img(self):
try:
imgur = "None"
download_img = True
print((colored('[+] Downloading image from Cloud Service...', 'white')))
while download_img:
# Remove not valid img downloaded
if (os.path.isfile(imgur)):
os.remove(imgur)
imgur = ''.join(random.sample(string.letters+string.digits, 5)) + '.jpg'
img = urllib2.urlopen("http://i.imgur.com/" + imgur).read()
if len(img) != 503: # 'image not found' is 503 bytes
with open(os.path.join('./', imgur), "wb") as f:
f.write(img)
f.close()
with Image.open(imgur) as im:
width, height = im.size
# Enough big to insert data
if (width > 400 and height > 400):
download_img = False
return imgur
except:
print((colored("[-] Get image error", "yellow")))
if (os.path.isfile(imgur)):
os.remove(imgur)
评论列表
文章目录