ogkalu2 / comic-translate

Desktop app for automatically translating comics - BDs, Manga, Manhwa, Fumetti and more in a variety of formats (Image, Pdf, Epub, cbr, cbz, etc) and in multiple languages.
Apache License 2.0
530 stars 47 forks source link

new feature proposal #26

Closed YasperMog1ot closed 2 weeks ago

YasperMog1ot commented 4 months ago

Could you please create a function that adds a white outline around the font

ayoosh007 commented 1 month ago

Someone already did that. Here's the code:

def draw_text(image: np.ndarray, blk_list: List[TextBlock], font_pth: str, init_font_size, colour: str = "#000"):
    image = cv2_to_pil(image)
    draw = ImageDraw.Draw(image)

    font = ImageFont.truetype(font_pth, size=init_font_size)

    for blk in blk_list:
        x1, y1, width, height = blk.xywh
        tbbox_top_left = (x1, y1)

        translation = blk.translation
        if not translation or len(translation) == 1:
            continue

        translation, font_size = pil_word_wrap(image, tbbox_top_left, font_pth, init_font_size, translation, width, height, align=blk.alignment, spacing=blk.line_spacing)
        font = font.font_variant(size=font_size)

        offsets = [(dx, dy) for dx in (-2, -1, 0, 1, 2) for dy in (-2, -1, 0, 1, 2) if dx != 0 or dy != 0]
        for dx, dy in offsets:
            draw.multiline_text((tbbox_top_left[0] + dx, tbbox_top_left[1] + dy), translation, font=font, fill="#FFF", align=blk.alignment, spacing=1)

        draw.multiline_text(tbbox_top_left, translation, colour, font, align=blk.alignment, spacing=1)
    image = pil_to_cv2(image)
    return image

Go to modules>rendering>render.py find the function with the same name and replace it with the code given

ogkalu2 commented 2 weeks ago

@YasperMog1ot This has been resolved now. Download the latest version