Rediones / utils /image_utils.py
Testys's picture
Upload 3 files
e67cd9e
raw
history blame
481 Bytes
import requests
from PIL import Image
import urllib.parse as parse
import os
# Verify url
def check_url(string):
try:
result = parse.urlparse(string)
return all([result.scheme, result.netloc, result.path])
except:
return False
# Load an image
def load_image(image_path):
if check_url(image_path):
return Image.open(requests.get(image_path, stream=True).raw)
elif os.path.exists(image_path):
return Image.open(image_path)