21 lines
647 B
Python
21 lines
647 B
Python
from PIL import Image
|
|
|
|
|
|
def size_processor(image: Image.Image):
|
|
width, height = image.size
|
|
if width > 500 or height > 500:
|
|
max_size = max(width, height)
|
|
ratio = 500 / max_size
|
|
new_width = int(width * ratio)
|
|
new_height = int(height * ratio)
|
|
image = image.resize((new_width, new_height), Image.Resampling.BILINEAR)
|
|
|
|
if width < 28 or height < 28:
|
|
min_size = min(width, height)
|
|
ratio = 28 / min_size + 1
|
|
new_width = int(width * ratio)
|
|
new_height = int(height * ratio)
|
|
image = image.resize((new_width, new_height), Image.Resampling.BILINEAR)
|
|
|
|
return image
|