def get_cropping_offset(crop, epsilon):
    """
    Calculates the cropping offset for the cropped image. This only calculates
    the offset for one dimension (X or Y). This should be called twice to get
    the offsets for the X and Y dimensions.

    :param str crop: A percentage cropping value for the plane. This is in the
        form of something like '50%'.
    :param float epsilon: The difference between the original image's dimension
        (X or Y) and the desired crop window.
    :rtype: int
    :returns: The cropping offset for the given dimension.
    """
    m = _CROP_PERCENT_PATTERN.match(crop)
    if not m:
        raise ThumbnailParseError('Unrecognized crop option: %s' % crop)
    value = int(m.group('value')) # we only take ints in the regexp
    unit = m.group('unit')
    if unit == '%':
        value = epsilon * value / 100.0
        # return ∈ [0, epsilon]
    return int(max(0, min(value, epsilon)))
Calculates the cropping offset for the cropped image. This only calculates
    the offset for one dimension (X or Y). This should be called twice to get
    the offsets for the X and Y dimensions.

    :param str crop: A percentage cropping value for the plane. This is in the
        form of something like '50%'.
    :param float epsilon: The difference between the original image's dimension
        (X or Y) and the desired crop window.
    :rtype: int
    :returns: The cropping offset for the given dimension.