def resize_image(file_path, max_size):
img = cv2.imread(file_path)
file_up_path, file_ext = os.path.splitext(file_path)
height, width, _ = img.shape
new_img_path = f"{file_up_path}_resize{file_ext}"
if max_size < width > height:
new_img = cv2.resize(img, (4096, int(height * (4096 / width))))
cv2.imwrite(new_img_path, new_img)
return new_img_path
if max_size < height > width:
new_img = cv2.resize(img, (round(width * (4096 / height)), 4096))
cv2.imwrite(new_img_path, new_img)
return new_img_path
return file_path