Nodes/ComfyUI-Pixel-Optimal-Wan/Image Optimal Pixel (Wan)
ComfyUI Node

Image Optimal Pixel (Wan)

Your Wan I2V keeps failing on resolution? This node snaps images to the x16 grid

By LahHalah·Created 5 months ago·Updated 5 months ago· 0
Image Optimal Pixel (Wan)
  • image
  • IMAGE
target_megapixels1.00

Every Wan 2.1/2.2 image-to-video user hits the same wall eventually: you load a perfectly good reference image, hit queue, and ComfyUI either throws a resolution error or silently pads your 1317×579 image into something the VAE can actually eat. Video models are pickier than image models about input dimensions, and Wan - the last open Wan, the one everyone's still building on - wants both width and height on a grid of 16. Image Optimal Pixel (Wan) is a two-input utility that rescales your image to a target megapixel count and snaps it onto that x16 grid in one step. It's tiny, it's free of dependencies, and it exists to kill the most boring failure mode in the Wan I2V pipeline.

Why Wan makes this necessary

Wan 2.2 is where local video generation consolidated - the MoE high/low-noise architecture, the more expressive motion, the 5-second 81-frame default. But that quality comes with guardrails. Its 3D causal VAE expects spatial dimensions divisible by 16; feed it anything off-grid and the workflow errors or crops in ways that are hard to debug. Wan is also a flow-matching model where your output resolution basically is your input resolution - the standard pipeline is "generate a still, then animate it," and that still needs to land on the grid at roughly your target megapixels.

ComfyUI's built-in ImageScaleToTotalPixels already does the "scale to N megapixels keeping aspect ratio" half of this, but it won't snap to the 16px grid. You'd be hand-calculating the next multiple of 16 for every image. That's exactly the busywork this node bakes in.

How it works

The whole thing is a few lines of math, and you can read them in the source:

  1. Read the image's aspect ratio, then compute the ideal width/height that hits target_megapixels × 1,000,000 while keeping that ratio.
  2. Round both dimensions to the nearest multiple of 16 (floor of 16).
  3. Resize with PIL bicubic, hand the tensor back as float32.

No model, no VRAM spike, no GPU work to speak of - it's a CPU-side resize. One honest caveat: because the x16 snapping wins, target_megapixels is a target, not an exact contract. Set 1.0 and a 16:9 image lands at 1328×752 rather than exactly 1,000,000 pixels. That's the tradeoff you want - grid alignment matters more than being pixel-exact.

The inputs that matter

There are exactly two, and you'll only ever touch one:

  • image - your source still (or video frames, if you feed it a clip; it resizes every frame).
  • target_megapixels (default 1.0, range 0.01–16.0) - the resolution you're aiming for. Match it to your generation target: 720p Wan output is ~0.9 MP (1280×720), 480p is ~0.4 MP (854×480). For the 5B/1.3B models on modest VRAM, go lower - 0.4–0.5 is a sane place to start.

The single IMAGE output wires straight into the image input of your Wan I2V loader/model node.

Installing it

It's a standard custom node, installable from ComfyUI Manager by searching "ComfyUI-Pixel-Optimal-Wan", or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/LahHalah/ComfyUI-Pixel-Optimal-Wan

Then restart ComfyUI. No requirements file ships, because there's nothing to install - it only imports torch, numpy, and Pillow, all already present in any ComfyUI. No model downloads, no extra checkpoints, nothing to configure. It just appears in your node list under image/resize.

Where it bites

  • Don't use it as an upscaler. Bicubic is fine for conditioning input that gets squashed into latents anyway, but it's soft if you're trying to blow up a reference for quality. Generate at native res or use a real upscaler (SeedVR2 or a tile-based pass) for the final output.
  • It's Wan-tuned, not universal. Some newer video models (LTX 2.3, for one) demand divisibility by 32, which this won't give you. It's the right tool for Wan's x16 rule specifically.
  • It fixes pixels, not frames. Wan also wants 4n+1 frame counts (81, 121…); this node only touches spatial dimensions. That's a separate problem.
  • The README is a title and nothing else. The pack's documentation is essentially nonexistent - this article and the source are the docs.

It won't change your life, but the first time a reference image queues without you staring at an error, you'll be glad it's in your graph.

Categoryimage/resize

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
target_megapixelsFLOAT1.000.01–16

Outputs (1)

NameTypeDescription
IMAGEIMAGE