Cropping images with Python

from PIL import Image

def crop_center_image(path, new_path, new_width=None, new_height=None):
    image = Image.open(path)
    width, height = image.size  # Get dimensions

    if (new_width is None or new_height is None):
        if width >= height:  # landscape crop
            new_width, new_height = height, height
        else:  # portrait crop
            new_width, new_height = width, width

    left = (width - new_width) / 2
    top = (height - new_height) / 2
    right = (width + new_width) / 2
    bottom = (height + new_height) / 2

    image = image.crop((left, top, right, bottom))
    image.save("{}-{}.{}".format(new_path, str(width), 'png'))