INNER CODE UNIT · Python
add_random_background
OpenVGLab/OmniLottie · app.py:86
def add_random_background(img):
if img.mode != 'RGBA':
return img.convert('RGB')
light_colors = [(255, 255, 255), (245, 245, 245), (250, 250, 250)]
bg_color = random.choice(light_colors)
background = PILImage.new('RGB', img.size, bg_color)
background.paste(img, (0, 0), img)
return background
def load_frames_from_video(video_path, num_frames=8, max_size=336):
import os
ext = os.path.splitext(video_path)[1].lower()
frames = []
if ext in ('.gif', '.webp'):
try: