from moviepy.editor import ImageClip, concatenate_videoclips from PIL import Image, ImageDraw, ImageFont import numpy as np images = [ "/mnt/data/0001.jpg", "/mnt/data/0001.png", "/mnt/data/0001(1).png", "/mnt/data/0001(2).png" ] texts = [ "Μοντέρνα Ξύλινα Σπιτάκια", "Ποιότητα & Άνεση", "Ιδανικά για Εξοχικό ή Επένδυση", "TaSpitakia.net | 99684007" ] clips = [] for img_path, text in zip(images, texts): img = Image.open(img_path).convert("RGB") img = img.resize((854, 480)) draw = ImageDraw.Draw(img) try: font = ImageFont.truetype("DejaVuSans.ttf", 30) except: font = ImageFont.load_default() bbox = draw.textbbox((0, 0), text, font=font) tw = bbox[2] - bbox[0] th = bbox[3] - bbox[1] x = (854 - tw) // 2 y = 420 draw.rectangle((x - 10, y - 5, x + tw + 10, y + th + 5), fill=(0, 0, 0)) draw.text((x, y), text, font=font, fill=(255, 255, 255)) frame = np.array(img) clip = ImageClip(frame).set_duration(2) clips.append(clip) final = concatenate_videoclips(clips) output = "/mnt/data/TaSpitakia_Ad.mp4" final.write_videofile(output, fps=12, codec="libx264", audio=False, preset="ultrafast") print("DONE", output)
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου