|
|
import os
|
|
|
from PIL import Image
|
|
|
import numpy as np
|
|
|
import torch
|
|
|
|
|
|
class LoadWebPAnimation:
|
|
|
@classmethod
|
|
|
def INPUT_TYPES(cls):
|
|
|
return {
|
|
|
"required": {
|
|
|
"path": ("STRING", {"default": ""}),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
|
FUNCTION = "load_animation"
|
|
|
|
|
|
def load_animation(self, path):
|
|
|
|
|
|
if not os.path.exists(path):
|
|
|
raise FileNotFoundError(f"File not found: {path}")
|
|
|
|
|
|
|
|
|
with Image.open(path) as img:
|
|
|
|
|
|
if hasattr(img, 'is_animated') and img.is_animated:
|
|
|
frames = []
|
|
|
|
|
|
for i in range(img.n_frames):
|
|
|
img.seek(i)
|
|
|
frame = img.copy().convert('RGB')
|
|
|
frames.append(np.array(frame))
|
|
|
batch = np.stack(frames, axis=0)
|
|
|
else:
|
|
|
|
|
|
frame = img.convert('RGB')
|
|
|
batch = np.expand_dims(np.array(frame), axis=0)
|
|
|
|
|
|
|
|
|
batch = batch.astype(np.float32) / 255.0
|
|
|
|
|
|
|
|
|
batch = torch.from_numpy(batch)
|
|
|
|
|
|
return (batch,)
|
|
|
|
|
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
|
"LoadWebPAnimation": LoadWebPAnimation
|
|
|
}
|
|
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
|
"LoadWebPAnimation": "Load WebP Animation"
|
|
|
} |