File size: 626 Bytes
79904b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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")