Skip to content

Commit

Permalink
Merge pull request #2270 from aaa3334/patch-3
Browse files Browse the repository at this point in the history
Add bg_radius to text boxes
  • Loading branch information
OsaAjani authored Jan 10, 2025
2 parents 10be13e + 99f8f3c commit 23834f6
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,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.
"""

@convert_path_to_string("filename")
Expand All @@ -1543,6 +1548,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 @@ -1802,9 +1808,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

0 comments on commit 23834f6

Please sign in to comment.