def _generate_image_url(cls, url, size, crop):
        """
        Try to generate an IG cropped  image url.

        :param url: target url
        :param size: width/height of the image
        :param crop: 'p' or 's'
        :return:
        """
        mobj = re.search(cls.IG_IMAGE_URL_EXPR, url)
        if not mobj:
            replacement_expr = r'\g<eparam>{crop!s}{size!s}x{size!s}/'.format(
                **{'crop': crop, 'size': size})
            return re.sub(r'(?P<eparam>/e[0-9]+/)', replacement_expr, url)
        replacement_expr = '/{crop!s}{size!s}x{size!s}/'.format(
            **{'crop': mobj.group('crop') or crop, 'size': size})
        return re.sub(cls.IG_IMAGE_URL_EXPR, replacement_expr, url)

        Try to generate an IG cropped  image url.

        :param url: target url
        :param size: width/height of the image
        :param crop: 'p' or 's'
        :return:
        
instagram_web_api/compatpatch.py