Ejemplo n.º 1
0
def generate_card_img_title_description(string: str, img_path: str, filename: str, font_size: int, x: int, y: int,
                                        color, char_limit, img_url, img_x, img_y, img_width, img_height,
                                        description: str, desc_x: int, desc_y: int, desc_font_size: int,
                                        font="opensans"):
    try:
        validate_chars_limit(string, char_limit)

        position = (x, y)
        img = Image.open(img_path)
        drawer = ImageDraw.Draw(img)
        drawer.text(position, string,
                    font=ImageFont.truetype(font=os.getcwd() + '/templates/fonts/' + font + '.ttf', size=font_size),
                    fill=color)

        drawer.text((desc_x, desc_y), description,
                    font=ImageFont.truetype(font=os.getcwd() + '/templates/fonts/' + font + '.ttf',
                                            size=desc_font_size),
                    fill=color)

        add_thumbnail_to_img(img, img_height, img_url, img_width, img_x, img_y)

        return parse_to_discord_file(img)

    except Exception as e:
        puts.info(e)
        raise FutebotException(e)
Ejemplo n.º 2
0
def generate_card_multiple_texts(img_path: str, filename: str, *texts: tuple):
    try:

        img = Image.open(img_path)
        drawer = ImageDraw.Draw(img)

        for text in texts:
            string = text[0]
            font_size = text[1]
            x = text[2]
            y = text[3]
            color = text[4]
            char_limit = text[5]
            font = text[6]

            validate_chars_limit(string, char_limit)

            position = (x, y)

            drawer.text(position, string,
                        font=ImageFont.truetype(font=os.getcwd() + '/templates/fonts/' + font + '.ttf',
                                                size=font_size),
                        fill=color)

        return parse_to_discord_file(img)

    except Exception as e:
        puts.info(e)
        raise FutebotException(e)
Ejemplo n.º 3
0
def generate_card_twit(name: str, display_name: str, img_path: str, filename: str, img_url, description: str):
    try:
        validate_chars_limit(description, 50)

        img = Image.open(img_path)
        drawer = ImageDraw.Draw(img)
        drawer.text((95, 30), name,
                    font=ImageFont.truetype(font=os.getcwd() + '/templates/fonts/helvetica.ttf', size=20),
                    fill=(0, 0, 0))

        drawer.text((90, 55), display_name,
                    font=ImageFont.truetype(font=os.getcwd() + '/templates/fonts/helvetica.ttf', size=18),
                    fill=(150, 150, 150))

        drawer.text((20, 100), description,
                    font=ImageFont.truetype(font=os.getcwd() + '/templates/fonts/helvetica.ttf', size=35),
                    fill=(0, 0, 0))

        response = requests.get(img_url, stream=True)

        img2 = Image.open(BytesIO(response.content))
        img2 = mask_circle_transparent(img2, 0)
        img2.thumbnail((60, 60), Image.ANTIALIAS)

        img.paste(img2, (20, 20), img2)

        return parse_to_discord_file(img)

    except Exception as e:
        puts.info(e)
        raise FutebotException(e)
Ejemplo n.º 4
0
def generate_card_img(string: str,
                      img_path: str,
                      filename: str,
                      font_size: int,
                      x: int,
                      y: int,
                      color,
                      char_limit,
                      img_url,
                      img_x,
                      img_y,
                      img_width,
                      img_height,
                      font="opensans"):
    try:
        validate_chars_limit(string, char_limit)
        img = draw_text_on_image(color, font, font_size, img_path, string, x,
                                 y)
        add_thumbnail_to_img(img, img_height, img_url, img_width, img_x, img_y)

        return parse_to_discord_file(img)

    except Exception as e:
        puts.info(e)
        raise FutebotException(e)
Ejemplo n.º 5
0
 def test_validate_chars_limit(self):
     """Test if string will be valid when under the limit"""
     try:
         validate_chars_limit("ABC", 5)
     except TooManyCharsException:
         fail(
             "validate_chars_limit() raised TooManyCharsException unexpectedly!"
         )
Ejemplo n.º 6
0
 def test_validate_chars_limit_exceeded(self):
     """Test if string will not be valid when over the limit"""
     with self.assertRaises(TooManyCharsException):
         validate_chars_limit("ABCDE", 4)