def resize_image(image_path, max_width, max_height, final_path):
    img = Image.open(image_path)

    width, height = img.size

    # Example, (max_width = 200) / (width = 400) = 0.5 (height must be half)
    wpercent   = max_width / float(width)
    # 0.5 * 400 = 200 px is the new height
    new_height = wpercent * height

    # If 200 > 200
    if new_height > max_height:
        # Then invert height and width
        new_height = max_height
        new_width  = width  * (max_height / float(height))
    else:
        # Otherwise, the new_width is half what it was
        new_width  = max_width

    new_size = int(new_width), int(new_height)

    img = img.resize( new_size, Image.ANTIALIAS)
    img.save(final_path)
dataset/ETHPy150Open weblabdeusto/weblabdeusto/server/src/weblab/admin/script/creation.py/resize_image/original