def resize_image(image, size=None, fx=1.0, fy=1.0):
    """Resize image to new size. If new_size is None, scaling factors fx and fy are used instead."""
    if size is None:
        width = int(fx * image.size[0])
        height = int(fy * image.size[1])
        new_size = (width, height)
    else:
        new_size = size

    return image.resize(new_size)