15 lines
474 B
Python
15 lines
474 B
Python
from PIL import Image
|
|
|
|
def resize(image, max_w=2048, max_h=2048):
|
|
cur_w, cur_h = image.width, image.height
|
|
image_bytes = image.samples
|
|
image = Image.frombytes("RGB", [cur_w, cur_h], image_bytes)
|
|
if cur_h > max_w or cur_h > max_h:
|
|
ratio_w = max_w/cur_w
|
|
ratio_h = max_h/cur_h
|
|
ratio = min([ratio_h, ratio_w])
|
|
new_w = int(ratio*cur_w)
|
|
new_h = int(ratio*cur_h)
|
|
image = image.resize((new_w, new_h))
|
|
|
|
return image |