bachelor-project / utils /image_utils.py
ZZZdream95's picture
All files
a7b41f5
raw
history blame contribute delete
474 Bytes
import io
from PIL import Image
from myapp.database.buckets.config import BUCKET_STORAGE_PREFIX
def remove_bucket_storage_prefix(url: str) -> str:
if url.startswith(BUCKET_STORAGE_PREFIX):
return url[len(BUCKET_STORAGE_PREFIX):]
return url
def get_image_stream(image_bytes: bytes):
return Image.open(io.BytesIO(image_bytes)).convert("RGB")
def get_RGBA_image_stream(image_bytes: bytes):
return Image.open(io.BytesIO(image_bytes)).convert("RGBA")