Download custom_nodes/dolphin_nodes/wan_resizer.py from bjooo/tutorials: direct link, hf CLI and curl.
- Browser
- Download file 2.4 kB
-
https://huggingface.co/bjooo/tutorials/resolve/main/custom_nodes/dolphin_nodes/wan_resizer.py
- Command line
-
hf download hf://bjooo/tutorials/custom_nodes/dolphin_nodes/wan_resizer.py
-
curl -L -o wan_resizer.py https://huggingface.co/bjooo/tutorials/resolve/main/custom_nodes/dolphin_nodes/wan_resizer.py
2.4 kB
| import math | |
| import torch | |
| import comfy.utils | |
| class WanNativeResize_Dolphin: | |
| def INPUT_TYPES(cls): | |
| return { | |
| "required": { | |
| "image": ("IMAGE",), | |
| "target_model": (["480P (832x480)", "720P (1280x720)", "1080P (1920x1080)"], {"default": "720P (1280x720)"}), | |
| "upscale_method": (["nearest-exact", "bilinear", "area", "bicubic", "lanczos"], {"default": "lanczos"}), | |
| "alignment": ("INT", {"default": 16, "min": 8, "max": 64, "step": 8}), | |
| } | |
| } | |
| RETURN_TYPES = ("IMAGE", "INT", "INT") | |
| RETURN_NAMES = ("IMAGE", "width", "height") | |
| FUNCTION = "resize_for_wan" | |
| CATEGORY = "Dolphin Node/Wan Video" | |
| def resize_for_wan(self, image, target_model, upscale_method, alignment): | |
| # 1. ComfyUI ์ด๋ฏธ์ง ํ ์์ ํํ๋ฅผ ๊ฐ์ ธ์ต๋๋ค: (Batch/Frames, Height, Width, Channels) | |
| b, h, w, c = image.shape | |
| # 2. ํ๊ฒ ๋ชจ๋ธ์ ๋ฐ๋ฅธ ์ด ํฝ์ ๋ฉด์ (Area) ์ธํ | |
| if "480P" in target_model: | |
| target_area = 832 * 480 | |
| elif "720P" in target_model: | |
| target_area = 1280 * 720 | |
| else: | |
| target_area = 1920 * 1080 | |
| # 3. Byungjoo๋์ ์ํ ๋ก์ง (๋น์จ ์ ์ง ๊ณ์ฐ) | |
| aspect_ratio = w / h | |
| new_h = math.sqrt(target_area / aspect_ratio) | |
| new_w = new_h * aspect_ratio | |
| # 4. [ํต์ฌ] VAE๊ฐ ์ข์ํ๋ ๋ฐฐ์(Alignment, ๋ณดํต 16)๋ก ๋ฐ์ฌ๋ฆผ ์ฒ๋ฆฌ | |
| new_w = int(round(new_w / alignment) * alignment) | |
| new_h = int(round(new_h / alignment) * alignment) | |
| # 5. [์ต์ ํ] ์ด๋ฏธ ๋ชฉํ ํด์๋์ ์ผ์นํ๋ค๋ฉด, ๋ฌด๊ฑฐ์ด ์ฐ์ฐ ์์ด ์๋ณธ ํต๊ณผ (ํจ์ค์ค๋ฃจ) | |
| if w == new_w and h == new_h: | |
| return (image, new_w, new_h) | |
| # 6. [ํต์ฌ] ํ ์ ์ฐจ์ ๋ณ๊ฒฝ: ComfyUI (B, H, W, C) -> ๋ฆฌ์ฌ์ด์ฆ ์์ง์ฉ (B, C, H, W) | |
| image = image.movedim(-1, 1) | |
| # 7. ComfyUI ๋ด์ฅ ์์ง์ ์ฌ์ฉํด ์ด๊ณ ํ์ง ๋ฆฌ์ฌ์ด์ฆ (Lanczos ์ง์) | |
| resized_image = comfy.utils.common_upscale(image, new_w, new_h, upscale_method, "disabled") | |
| # 8. ํ ์ ์ฐจ์ ์์ ๋ณต๊ตฌ: (B, C, H, W) -> ComfyUI (B, H, W, C) | |
| resized_image = resized_image.movedim(1, -1) | |
| return (resized_image, new_w, new_h) |