Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MoviePy2: When applying Stroke to a TextClip, some parts of the stroke is missing #2268

Open
rockfarmor opened this issue Dec 1, 2024 · 3 comments
Labels
bug Issues that report (apparent) bugs. text Issues dealing with TextClip, SubtitlesClip, or handling of text in general. v2.x Issues based on MoviePy version 2.0 and upwards

Comments

@rockfarmor
Copy link

rockfarmor commented Dec 1, 2024

Expected Behavior

When displaying a TextClip with stroke, the entire TextClip (including the stroke) should be visible without the need of adding a margin.

This image was rendered using margin=(10,10) on the TextClip.

test

Actual Behavior

When displaying a TextClip with stroke, parts of the stroke isn't rendered since it's outside of the TextClip's bounding box

test_margin

This might be intentional (Or separate issue), but it looks like the text isn't properly centered within the TextBox bounding box.

Steps to Reproduce the Problem

from moviepy import *
font = "font.ttf"
cc = ColorClip((500,200), (255,0,0,255)).with_duration(10)
    
txt_clip = TextClip(text="Hello", font=font, font_size=72, stroke_color="blue", stroke_width=10).with_duration(10)
txt_clip_with_margin = TextClip(text="Hello", font=font, font_size=72, stroke_color="blue", stroke_width=10, margin=(10,10)).with_duration(10)
    
comp = CompositeVideoClip([cc, txt_clip.with_position(("center", "center"))]).with_fps(24)
comp_margin = CompositeVideoClip([cc, txt_clip_with_margin.with_position(("center", "center"))]).with_fps(24)
    
comp.save_frame("test.png")
comp_margin.save_frame("test_margin.png")

Specifications

  • Python Version: 3.11.3
  • MoviePy Version: 2.1.1
  • Platform Name: Windows 11
  • Platform Version:
@rockfarmor rockfarmor added the bug Issues that report (apparent) bugs. label Dec 1, 2024
@rockfarmor rockfarmor changed the title When applying Stroke to a TextClip, some parts of the stroke is missing MoviePy2: When applying Stroke to a TextClip, some parts of the stroke is missing Dec 1, 2024
@keikoro keikoro added text Issues dealing with TextClip, SubtitlesClip, or handling of text in general. v2.x Issues based on MoviePy version 2.0 and upwards labels Dec 8, 2024
@OsaAjani
Copy link
Collaborator

I'm working on that one, should be able to provide a fix soon

@OsaAjani
Copy link
Collaborator

Hi, this one as well as the two other related issues should be fixed with the merging of the pr #2326.

Please try using the current master branch and tell me if things are better.

tl;dr: Considering you use the same settings, for a same number of line, the height of TextClip will always be the same. It might seem a bit to big, but it will be reliable and correctly aligned.

For everyone to understand how the new version works:

  • We use baseline as anchor (see https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html)
  • If you use label method and let the size of the TextClip be auto-calculated, the resulting clip will be of the maximum possible size the text could be. Meaning the TextClip size will be calculated as if your first and last line both contains characters with ascent (e.g an upper letter with some kind of accent) and descent (e.g y, p, j, g, etc.).
  • If your first and last line does not include such characters, your TextClip could be bigger than the real size of your text. Its not perfect, but its reliable.

@GrayFL
Copy link

GrayFL commented Jan 20, 2025

Although I haven't made a particularly detailed comparison to check if there are differences between the current version and v1.0, the issues of text cropping and incorrect alignment have indeed been resolved at present. Thank you very much for your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs. text Issues dealing with TextClip, SubtitlesClip, or handling of text in general. v2.x Issues based on MoviePy version 2.0 and upwards
Projects
None yet
Development

No branches or pull requests

4 participants