Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #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)
Beispiel #5
0
def generate_card(string: str,
                  img_path: str,
                  filename: str,
                  font_size: int,
                  x: int,
                  y: int,
                  color,
                  char_limit,
                  font="opensans"):
    try:

        if len(
                string
        ) >= char_limit:  # 23 or bigger string would cut the text out, for now just avoid it.
            raise TooManyCharsException("Diminue esse textão aí, pfv.")

        else:
            position = (x, y)
            img = Image.open(img_path)
            drawer = ImageDraw.Draw(img)
            drawer.text(position,
                        string,
                        font=ImageFont.truetype(font='templates/fonts/' +
                                                font + '.ttf',
                                                size=font_size),
                        fill=color)
            img_url = save_image_to_imgur(image_to_byte_array(img))
            image_is_valid, file_bytes = validate_image(img_url)
            discord_file = create_discord_file_object(file_bytes, ".png")
            return discord_file

    except Exception as e:
        puts.info(e)
        raise FutebotException(e)
Beispiel #6
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]

            if len(
                    string
            ) >= char_limit:  # 23 or bigger string would cut the text out, for now just avoid it.
                raise TooManyCharsException("Diminue esse textão aí, pfv.")

            else:
                position = (x, y)

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

        img_url = save_image_to_imgur(image_to_byte_array(img))
        image_is_valid, file_bytes = validate_image(img_url)
        discord_file = create_discord_file_object(file_bytes, ".png")
        return discord_file

    except Exception as e:
        puts.info(e)
        raise FutebotException(e)