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

Add bg_radius to text boxes #2270

Merged
merged 4 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,11 @@ class TextClip(ImageClip):

duration
Duration of the clip

bg_radius
A paramater to round the edges of the text background. Defaults to 0 if there
is no background. It will have no effect if there is no bg_colour added.
The higher the value, the more rounded the corners will become.
Comment on lines +1443 to +1445
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A paramater to round the edges of the text background. Defaults to 0 if there
is no background. It will have no effect if there is no bg_colour added.
The higher the value, the more rounded the corners will become.
Round the edges of the text background. Defaults to 0, and has no
effect if bg_color is not set.
The higher the value, the more rounded the corners will become.

"""

@convert_path_to_string("filename")
Expand All @@ -1460,6 +1465,7 @@ def __init__(
interline=4,
transparent=True,
duration=None,
bg_radius=0, # TODO : Move this with other bg_param on next breaking release
):
def break_text(
width, text, font, font_size, stroke_width, align, spacing
Expand Down Expand Up @@ -1719,9 +1725,20 @@ def find_optimum_font_size(
if bg_color is None and transparent:
bg_color = (0, 0, 0, 0)

img = Image.new(img_mode, (img_width, img_height), color=bg_color)
pil_font = ImageFont.truetype(font, font_size)
draw = ImageDraw.Draw(img)
if bg_radius is None:
bg_radius = 0

if bg_radius != 0:
img = Image.new(img_mode, (img_width, img_height), color=(0, 0, 0, 0))
pil_font = ImageFont.truetype(font, font_size)
draw = ImageDraw.Draw(img)
draw.rounded_rectangle(
[0, 0, img_width, img_height], radius=bg_radius, fill=bg_color
)
else:
img = Image.new(img_mode, (img_width, img_height), color=bg_color)
pil_font = ImageFont.truetype(font, font_size)
draw = ImageDraw.Draw(img)

# Dont need allow break here, because we already breaked in caption
text_width, text_height = find_text_size(
Expand Down
1 change: 0 additions & 1 deletion moviepy/video/fx/Scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(
y_start=0,
apply_to="mask",
):

self.w = w
self.h = h
self.x_speed = x_speed
Expand Down
12 changes: 6 additions & 6 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ def parse(self):
# for default streams, set their numbers globally, so it's
# easy to get without iterating all
if self._current_stream["default"]:
self.result[f"default_{stream_type_lower}_input_number"] = (
input_number
)
self.result[f"default_{stream_type_lower}_stream_number"] = (
stream_number
)
self.result[
f"default_{stream_type_lower}_input_number"
] = input_number
self.result[
f"default_{stream_type_lower}_stream_number"
] = stream_number

# exit chapter
if self._current_chapter:
Expand Down
Loading