Charles Kabui
loading images
79904b0
raw
history blame
626 Bytes
from PIL import Image
from urllib.parse import urlparse
import requests
def is_online_file(url: str) -> bool:
return urlparse(url).scheme in ["http", "https"]
def steam_online_file(url: str) -> bytes:
return requests.get(url, stream=True).raw
def get_RGB_image(image_or_path: str | Image.Image) -> bytes:
if isinstance(image_or_path, str):
if is_online_file(image_or_path): # Online
content = steam_online_file(image_or_path)
image_or_path = Image.open(content)
else: # Local
image_or_path = Image.open(image_or_path)
return image_or_path.convert("RGB")