Nodes/jlc-comfyui-nodes/ JLC Load, Resize & Encode Image
ComfyUI Node

 JLC Load, Resize & Encode Image

The image loader that ends 'latent size mismatch' errors

By Damkohler·Created 6 months ago·Updated 3 days ago· 24
 JLC Load, Resize & Encode Image
  • vae
  • image
  • mask
  • width
  • height
  • latent
image
resize_byscale longer dimension
multiplier1.00
longer_size1024
shorter_size1024
width1024
height1024
megapixels1.00
scale_methodarea
divisible_by16

Load a reference image, drag an inpaint mask onto the canvas, and the moment you hit "Queue" the run dies because your image is 833×611 and the model wants dimensions divisible by 8. JLC Load & Resize Image exists so that stop being a problem. It's a drop-in image loader that resizes the image and its mask together, preserves aspect ratio, and rounds the final dimensions down to whatever multiple you need - 16 by default - so the output actually fits the latent space. It's from jlc-comfyui-nodes (J. L. Córdova / Damkohler), and it's modeled on the KJNodes "Load & Resize Image" idea without requiring KJNodes itself.

How it works

Under the hood it subclasses ComfyUI's own LoadImage, so you get the exact upload / drag-and-drop contract you already know - the image widget is a dropdown plus upload button, drag a file onto the node and it lands in your input folder. Then the resize logic kicks in. Unlike a freeform width/height resize node, every mode here preserves aspect ratio; the divisible_by rounding happens after, and it rounds down (never silently upscaling your image) and clamps a tiny edge to one divisor so output stays valid.

The part beginners miss until they hit it: the mask output is resized to exactly the same dimensions as the image, and images with no alpha still get a correctly sized all-zero mask. That lockstep behavior is why you don't get the classic mismatch where your mask is a different size than your image and the inpaint node refuses to cooperate.

The inputs that matter

Pick your resize mode with resize_by, and the frontend shows only the numeric widget that mode uses:

  • scale by multipliermultiplier (2.0 doubles both dimensions)
  • scale longer dimensionlonger_size (default 1024)
  • scale shorter dimensionshorter_size
  • scale widthwidth, or scale heightheight (the other edge is derived from aspect ratio)
  • scale total pixelsmegapixels (1024×1024 per megapixel)

Then two settings apply everywhere: scale_method (area for downscaling, lanczos for upscaling - the tooltips' own advice) and divisible_by (default 16; use 1 to disable). For Flux workflows people often want 16 or 32; for most SDXL-era models 8 is enough. If you've ever fought a "latent size mismatch," this is the widget that does the fighting for you.

Outputs are image (BHWC), mask (BHW), and two INTs - width and height. Those INTs are the quiet MVP here: wire them into an Empty Latent's width/height and your sampling resolution is guaranteed to match what the node produced.

Install

ComfyUI Manager (search JLC ComfyUI Nodes, it's on the registry), or:

cd ComfyUI/custom_nodes
git clone https://github.com/Damkohler/jlc-comfyui-nodes.git

Restart after installing or git pull-ing. No model downloads and no extra Python dependencies for this node.

Honest positioning

If you already run KJNodes, its Load & Resize Image does the same job and you don't need this one. But within a JLC pack, this node pairs naturally with the Padded Image / Padded Latent utilities for inpainting and outpainting workflows - load a source at the right aspect ratio, pad it onto a canvas, and the dimensions all stay consistent. The one thing it deliberately does not do is let you set width and height independently and squish the aspect ratio - that's a feature, not a bug, and if that's what you actually need, a plain Resize node is the tool. For everything else, this loader quietly removes a whole class of "why won't my workflow run" errors.

Categoryutils/image

Inputs (11)

NameTypeDefaultDescription
imageCOMBO1 options: example.png
resize_byCOMBOscale longer dimensionAspect-ratio-preserving resize policy. The frontend shows only the numeric control used by this mode.
multiplierFLOAT1.000.01–8Scale factor; 2.0 doubles both dimensions.
longer_sizeINT10241–16384Target size of the source image's longer edge.
shorter_sizeINT10241–16384Target size of the source image's shorter edge.
widthINT10241–16384Target width; height is calculated from aspect ratio.
heightINT10241–16384Target height; width is calculated from aspect ratio.
megapixelsFLOAT1.000.01–64Target total megapixels using 1024×1024 per megapixel.
scale_methodCOMBOareaInterpolation method. Area is generally strong for downscaling; Lanczos is often useful for upscaling.
divisible_byINT161–512After aspect-ratio calculation, round width and height down to this multiple. Use 1 to disable.
vaeoptVAEOptional. When connected, encodes the final resized IMAGE and returns it through the LATENT output. Without a VAE, LATENT returns None.

Outputs (5)

NameTypeDescription
imageIMAGE
maskMASK
widthINT
heightINT
latentLATENT