Skip to content

Video editing with Python

Update VideoClip.py

aaa3334284df38cb948
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index fd43a81a..dce433b4 100644
--- a/moviepy/video/VideoClip.py
+++ b/moviepy/video/VideoClip.py
@@ -1405,6 +1405,12 @@ class TextClip(ImageClip):
a RGB (or RGBA if transparent = ``True``) ``tuple``, a color name, or an
hexadecimal notation.
+ 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.
+
+
stroke_color
Color of the stroke (=contour line) of the text. If ``None``,
there will be no stroke.
@@ -1451,6 +1457,7 @@ class TextClip(ImageClip):
margin=(None, None),
color="black",
bg_color=None,
+ bg_radius=0,
stroke_color=None,
stroke_width=0,
method="label",
@@ -1719,9 +1726,19 @@ class TextClip(ImageClip):
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(