def _crop(im, target_x, target_y):
    """
    Crops the image to the given specifications.

    :param im: Instance of the image.
    :type im: PIL Image
    :param target_x: New x-axis.
    :type target_x: int
    :param target_y: New y-axis
    :type target_y: int
    :return: Cropped image.
    :rtype: PIL.Image
    """
    source_x, source_y = im.size
    diff_x = int(source_x - min(source_x, target_x))
    diff_y = int(source_y - min(source_y, target_y))
    if diff_x or diff_y:
        halfdiff_x, halfdiff_y = diff_x // 2, diff_y // 2
        box = [halfdiff_x, halfdiff_y, min(source_x, int(target_x) +
            halfdiff_x), min(source_y, int(target_y) + halfdiff_y)]
        im = im.crop(box)
    return im
