Ejemplo n.º 1
0
def draw_quote(pil_image, quote):
    """
    :param pil_image: PIL.Image object
    :param quote: quote
    :param sd_source: reduce stroke_width for low-res sources
    :raises exceptions.OffensiveWord
    """
    logger.info("Drawing subtitle")

    check_offensive_content(quote)
    quote = prettify_quote(clean_sub(quote))

    draw = ImageDraw.Draw(pil_image)

    width, height = pil_image.size
    font_size = int((width * 0.019) + (height * 0.019))
    font = ImageFont.truetype(FONT, font_size)
    # 0.067
    off = width * 0.08
    txt_w, txt_h = draw.textsize(quote, font)

    stroke = int(width * 0.0025)

    draw.text(
        ((width - txt_w) / 2, height - txt_h - off),
        quote,
        "white",
        font=font,
        align="center",
        stroke_width=stroke,
        stroke_fill="black",
    )

    return pil_image
Ejemplo n.º 2
0
def de_quote_sub(text):
    return clean_sub(text).replace('"', "")