emosaic-backend / app /image_processor.py
Samidha21's picture
add app files
42b209f
Raw History Blame Contribute Delete
723 Bytes
import numpy as np
from PIL import Image
def load_image(file):
image = Image.open(file)
# Convert everything to RGB
image = image.convert("RGB")
return image
def resize_image(image, resolution):
width, height = image.size
# Clamp resolution
resolution = max(40, min(300, resolution))
aspect_ratio = width / height
if width >= height:
new_width = resolution
new_height = int(resolution / aspect_ratio)
else:
new_height = resolution
new_width = int(resolution * aspect_ratio)
resized = image.resize(
(new_width, new_height),
Image.LANCZOS
)
return resized
def image_to_array(image):
return np.array(image)