示例#1
0
 def create_thumbnail(self, clip: Clip):
     logging.info("Creating yt thumbnail")
     thumbnail_base = self.get_thumbnail_base(clip)
     emoji = self.get_emoji()
     overlay = ImageClip(os.path.join(self.asset_path, "overlay_thumbnail.png")).set_opacity(0.8)
     number = self.get_number_textclip()
     try:
         logo = (
             ImageClip(os.path.join(self.asset_path, utils.get_valid_game_name(self.game), "game_logo.png"))
             .fx(resize, 1.3)
             .set_position((0.04, 0.6), relative=True)
         )
     except FileNotFoundError:
         logging.warning("No game_logo in associated asset folder -> thumbnail will be created without logo")
         logo = None
     thumbnail = [
         thumbnail_base.set_duration(None),
         emoji.set_duration(None),
         overlay.set_duration(None),
         number.set_duration(None),
     ]
     if logo:
         thumbnail.append(logo.set_duration(None))
     thumbnail_result = CompositeVideoClip(thumbnail, size=[1280, 720])
     thumbnail_result.save_frame(os.path.join(self.compilation_dir, "thumbnail.png"), t=0, withmask=True)
示例#2
0
def make(resolution=(3840, 2160),
         blur=0,
         debug_mode=False,
         gradient_opacity=1,
         file_name=''):

    # opens art, then adds blur, then blows up
    art_image = Image.open('lib/temp/art.png')
    art_image = art_image.filter(ImageFilter.GaussianBlur(radius=blur))
    if (resolution > art_image.size):
        if debug_mode:
            print('Art smaller than background needed')
        art_image = art_image.resize(
            (math.ceil(resolution[0] * 1.05), math.ceil(resolution[0] * 1.05)),
            Image.ANTIALIAS)
    else:
        if debug_mode:
            print('Art larger than background needed')
    if debug_mode:
        print('Background size before crop: ' + str(art_image.size))

    # cropping the blurred art
    width, height = art_image.size

    left = (width - resolution[0]) / 2
    top = (height - resolution[1]) / 2
    right = (width + resolution[0]) / 2
    bottom = (height + resolution[1]) / 2

    # crop
    art_image = art_image.crop((left, top, right, bottom))

    art_image.save('lib/temp/' + file_name + '.png', 'PNG')
    art_image.close()

    # determines if the art is dark with is_dark
    if is_dark.calc(debug_mode=debug_mode):
        if debug_mode:
            print('Detected dark art; using white gradient')
        gradient_clip = ImageClip(
            'themes/radio/gradient_white.png',
            transparent=True).set_opacity(gradient_opacity)
    else:  # its light
        if debug_mode:
            print('Detected light art; using black gradient')
        gradient_clip = ImageClip(
            'themes/radio/gradient_black.png',
            transparent=True).set_opacity(gradient_opacity)

    gradient_clip.resize(resolution)
    art_clip = ImageClip('lib/temp/' + file_name + '.png', transparent=True)
    transparent = ImageClip('lib/transparent.png').resize(resolution)

    # again, the transparent needs to go first, this is to force a given resolution
    background_clip = CompositeVideoClip(
        [transparent, art_clip, gradient_clip])
    background_clip.save_frame('lib/temp/' + file_name + '.png')
示例#3
0
文件: video.py 项目: andyshinn/usb
    def thumbnail(self, time, dest, text):
        text_clip = VideoFile._generate_text(text)
        text_clip.duration = self.video_clip.duration
        video = CompositeVideoClip([self.video_clip, text_clip])
        video.duration = self.video_clip.duration

        try:
            video.save_frame(dest, t=(time + 1.0))
            logger.info("writing out thumbnail: {}", dest)
        except ValueError:
            logger.opt(
                exception=True).debug("Exception logged with debug level:")
示例#4
0
from moviepy.editor import ImageClip, TextClip, CompositeVideoClip
import os

watermark = "watermarker by azsry"

textclips = []

img_path = str(
    input("Drag the image you want to be watermarked into this window: "))
save_folder = os.path.dirname(img_path)
filename = os.path.splitext(os.path.basename(img_path))[0]
image = ImageClip(img_path)

ypos = -image.h

while ypos <= image.h:
    xpos = -image.w
    while xpos <= image.w:
        text = TextClip(watermark, fontsize=36, color='white')
        text_masked = text.add_mask().rotate(30).set_opacity(0.1).set_position(
            (xpos, ypos))

        textclips.append(text_masked)

        xpos = xpos + text.w
    ypos = ypos + (text.h * 2)

result = CompositeVideoClip([image, *textclips])
result.save_frame(f"{save_folder}\\{filename}_watermarked.png")