File size: 652 Bytes
89c627d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import io
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 io.BytesIO(requests.get(url, stream=True).content)

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")