backup but I will be reverting this.
This commit is contained in:
1 parent
1a4edfafca
commit
d9d62e252c
1 file changed
+13
-41
+13
-41
@@ -1,8 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from moviepy.video.VideoClip import VideoClip, ImageClip
|
||||
from typing import Tuple
|
||||
|
||||
from moviepy.video.VideoClip import VideoClip, TextClip
|
||||
from moviepy.video.io.VideoFileClip import VideoFileClip
|
||||
from PIL import Image, ImageDraw, ImageFont, ImageEnhance
|
||||
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
||||
|
||||
|
||||
class Video:
|
||||
def __init__(self, video: VideoClip | VideoFileClip, *args, **kwargs):
|
||||
@@ -11,45 +14,14 @@ class Video:
|
||||
self.duration = self.video.duration
|
||||
|
||||
@staticmethod
|
||||
def _create_watermark(text, path, fontsize=15, opacity=0.5):
|
||||
def _create_watermark(text, fontsize, opacity=0.5):
|
||||
txt_clip = TextClip(text, fontsize=fontsize, color='black').set_opacity(opacity)
|
||||
return txt_clip
|
||||
|
||||
width = 500
|
||||
height = 200
|
||||
def add_watermark(self, text, opacity=0.5, position: Tuple = (0.95, 0.95), fontsize=15):
|
||||
txt_clip = self._create_watermark(text, opacity=opacity, fontsize=fontsize)
|
||||
txt_clip = txt_clip.set_pos(position).set_duration(10)
|
||||
|
||||
white = (255, 255, 255)
|
||||
transparent = (0, 0, 0, 0)
|
||||
|
||||
font = ImageFont.load_default()
|
||||
wm = Image.new('RGBA', (width, height), transparent)
|
||||
im = Image.new('RGBA', (width, height), transparent) # Change this line too.
|
||||
|
||||
draw = ImageDraw.Draw(wm)
|
||||
w, h = draw.textsize(text, font)
|
||||
draw.text(((width - w) / 2, (height - h) / 2), text, white, font)
|
||||
en = ImageEnhance.Brightness(wm) # todo alow it to use the fontsize
|
||||
mask = en.enhance(1 - opacity)
|
||||
im.paste(wm, (25, 25), mask)
|
||||
im.save(path)
|
||||
|
||||
def add_watermark(self, text, opacity=0.5):
|
||||
# add a watermark to the video clip with the given text and opacity without importing a new library
|
||||
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
||||
from moviepy.video.compositing.concatenate import concatenate_videoclips
|
||||
path = './assets/temp/png/watermark.png'
|
||||
self._create_watermark(text, path, opacity=opacity)
|
||||
image_clips = []
|
||||
image_clips.insert(
|
||||
0,
|
||||
ImageClip(path)
|
||||
.set_duration(self.video.duration)
|
||||
#.resize(width=W - 100)
|
||||
)
|
||||
image_concat = concatenate_videoclips(image_clips).set_position((0.1, 0.1))
|
||||
self.video = CompositeVideoClip([self.video, image_concat])
|
||||
# Overlay the text clip on the first video clip
|
||||
self.video = CompositeVideoClip([self.video, txt_clip])
|
||||
return self.video
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__': # todo delete
|
||||
Video._create_watermark('Background Video by Jason(example)', '../assets/temp/png/watermark.png')
|
||||
Reference in new issue
Block a user