Nodes/JosiaNodes/Josia图像编码
ComfyUI Node

Josia图像编码

The Load Image / Resize / VAE Encode chain, in one node

By Josia-doit·Created 7 months ago·Updated 4 days ago· 37
Josia图像编码
  • image_in
  • mask
  • vae
  • 图像
  • 遮罩
  • Latent
◄缩放类型按系数缩放►
◄缩放系数1.00►
◄长边尺寸1024►
◄短边尺寸768►
◄百万像素1.00►
◄对齐倍数16►
◄通道切换自动►
◄VAE模型请选择VAE模型►
◄image🖼️请选择或上传图像…►

If you've built an img2img graph in ComfyUI, you know the ritual: Load Image → Image Scale → VAE Encode → sampler. Three nodes, two sizing decisions that must agree, and one wire you always forget. JosiaImageEncode (displayed as Josia图像编码) collapses that into a single box that hands you back the image, a mask, and the latent, already at the size you asked for.

What it is, and when you'd reach for it

It's the "turn a picture into something a sampler can eat" node - a drop-in replacement for Load Image on img2img, inpainting prep, or reference-latent workflows. The reason to switch isn't features, it's the graph: instead of a loader, a scaler and an encoder each holding a piece of the sizing, you get one node with one size decision and a latent output you can unplug.

It ships inside ComfyUI_JosiaNodes, a Chinese-language utility pack from the Bilibili creator 吉客AI (JeekAI). Be warned: every widget label and tooltip here is Chinese - 缩放类型, 对齐倍数, 通道切换 - which is the whole reason this pack has essentially zero English-language footprint.

How it works

Loading follows the native Load Image convention: 选择图像 lists files in ComfyUI/input/ with the standard upload button, or you wire an upstream IMAGE instead - the port wins and the dropdown greys out. If the source PNG has alpha, that becomes a mask, and the node separately re-reads the raw alpha off disk so it can put real transparency back into the fourth channel later.

Resizing happens on the numpy/PIL side rather than via torch: the image uses BOX (fastest, and you're about to encode it anyway), the mask uses NEAREST so edges don't smear. Then 对齐倍数 floors width and height to a multiple of 2/4/8/16/32/64 - default 16, which is what almost every VAE latent wants. Read the fine print: alignment only crops or shrinks, never upscales, and 缩放类型 = 关 skips scaling and alignment entirely.

The interesting bit is the latent gate. ComfyUI hands the node the whole prompt graph through hidden inputs, and the node checks whether the Latent output (third slot) is wired to anything. If it isn't, no VAE is loaded and no encode happens - you just get a resized image passthrough. So you can leave it bolted into a workflow permanently: connect Latent for img2img, disconnect it for text-to-image, no node surgery.

The controls that actually matter

缩放类型 is the top switch and the only one you touch most days: 关 (no scaling), 按系数缩放 (by factor), 按长边缩放 (long edge), 按短边缩放 (short edge), 按像素缩放 (megapixels). Whichever you pick, the single parameter row underneath morphs into the matching field - 缩放系数 (default 1.0), 长边尺寸 (1024), 短边尺寸 (768), or 百万像素 (1.0) - so there's no way to set a contradictory pair. The rest:

  • 通道切换 - 自动 passes through whatever channel count came in; RGB forces three channels and routes transparency out the 遮罩 port instead; RGBA forces four and fills alpha from the mask when the mask output is connected.
  • VAE模型 - defaults to 请选择VAE模型 (don't encode). 使用Josia模型加载VAE reuses the VAE already loaded by the pack's checkpoint node; otherwise pick one from models/vae. Wiring the VAE port greys this out.
  • 选择图像 - pick or upload; greys out when the image port is wired.

Outputs are 图像 (IMAGE), 遮罩 (MASK) and Latent (LATENT). In practice you wire Latent into the sampler's latent_image (it replaces VAE Encode) and 遮罩 into whatever your inpainting setup wants. Only the first three channels ever go to the VAE - alpha isn't encoded.

Install

There are no extra dependencies. The pack's requirements.txt literally says so, and pyproject.toml declares an empty dependency list - everything is ComfyUI's bundled torch/numpy/Pillow. Nothing to download either, beyond the VAE you're expected to already have.

cd ComfyUI/custom_nodes
git clone https://github.com/Josia-doit/ComfyUI_JosiaNodes
# restart ComfyUI

Success looks like [JosiaNodes] ✅ JosiaNodes 加载成功,注册节点数:18 in the console. ComfyUI Manager will find it by pack title, but the README is upfront that the pack ships mainly via git and hasn't guaranteed passing the registry's automated safety scan (older versions were flagged over a folder-picker routine in a different node). If Manager hides it, clone manually. And when you update, delete the pack folder rather than unzipping over it - stale filenames are a known source of duplicate frontend extensions.

Where people get burned

A black frame with no error. If neither the port nor the dropdown has an image, the node doesn't complain - it outputs a black image at the target size plus an all-opaque mask. An empty file slot looks like a result. Check the node preview before you debug anything else.

Transparent PNGs look black. Preview only draws RGB, and in PNGs the RGB under a fully transparent pixel is usually 0 - so it renders as a black square. This node paints those pixels white for the preview only; the real alpha still rides in channel four and on the 遮罩 port (bright = transparent, matching native Merge Image Alpha). Your pixels are fine.

"Latent 输出已连接,但没有可用的 VAE". You wired the latent output but left VAE模型 on the placeholder and the VAE port empty. Pick a VAE, wire one, or let the pack's checkpoint node supply it - and make sure it's the autoencoder your checkpoint was trained against. A mismatched VAE gives noise or flat colour, not a subtle shift.

The size isn't what you typed. Alignment rounds down. 缩放类型 = 关 disables alignment too, so if you want your input pixels back untouched, that's the setting.

Category⚡️JosiaNodes

Inputs (12)

NameTypeDefaultDescription
缩放类型COMBO按系数缩放决定图像怎么缩放,下方唯一缩放参数会随它**变形**(参考「调整图像/掩码大小」): • 关 = 完全不缩放、不对齐,下方缩放参数隐藏、对齐倍数灰化 • 按系数缩放 = 下方出现「缩放系数」(默认 1.0:不缩放,只按对齐倍数贴合) • 按长边缩放 = 下方出现「长边尺寸」:让最长边落到该像素,另一边等比跟随 • 按短边缩放 = 下方出现「短边尺寸」:让最短边落到该像素,另一边等比跟随 • 按像素缩放 = 下方出现「百万像素」:按总像素(百万)缩放,比例不变 缩放方法内部锁定为速度最快的 BOX(图像)/ NEAREST(遮罩),无需手动设置。
缩放系数FLOAT1.000.01–16按系数缩放时的倍率:默认 1.0 = 不缩放、只按对齐倍数贴合;0.5=缩一半,2.0=放大一倍。(仅「缩放类型=按系数缩放」时显示)
长边尺寸INT102432–8192按长边缩放时的目标最长边像素值;另一边等比跟随。(仅「缩放类型=按长边缩放」时显示)
短边尺寸INT76832–8192按短边缩放时的目标最短边像素值;另一边等比跟随。(仅「缩放类型=按短边缩放」时显示)
百万像素FLOAT1.000.01–64按像素缩放时的目标总像素(百万):1.0 ≈ 100 万像素(约 1024×1024),比例不变。(仅「缩放类型=按像素缩放」时显示)
对齐倍数COMBO16把输出宽高对齐到该数字的整数倍(16 适配绝大多数 VAE 潜空间)。 对齐只裁切 / 只缩小,绝不放大。 「缩放类型 = 关」时本项灰化不起作用。
通道切换COMBO自动决定「图像」端口输出几通道(本节点恒定另出一路「遮罩」单通道,也就是 3+1 里的那 +1): • 自动 = 上游给几通道就透传几通道:三通道进 ⇒ 三通道出,四通道进 ⇒ 四通道出。最省心。 • RGB = 强制三通道(RGB)。第四通道(透明度)不跟图像走,改成从「遮罩」端口出来,遮罩越亮=越透明(与原生加载图像一致的口径)。 • RGBA = 强制四通道(RGB + A),要**透明出图**就用它。第四通道的透明度按下面顺序取 —— ① 从「遮罩」**输入**端口喂了**外部**遮罩,就把它合并进 alpha(alpha = 1 − 遮罩,遮罩亮=透明,等于把原生「合并图像Alpha」内置进来);② 没喂外部遮罩时,图像自带的透明度(上传 PNG 的 alpha / 遮罩编辑器烘焙的透明度 / 上游四通道)原样保留;③ 什么透明度来源都没有 ⇒ 补一路全不透明。 注:「遮罩」输出端口在任何模式下都会给出一路(遮罩亮=越透明),与图像通道数无关。 说明:上游是灰度等其它通道数时一律按三通道处理;三种模式下喂给 VAE 编码的都只有前三通道。 透明度说明:完全透明的像素在预览里一律按白色呈现(预览只画 RGB,PNG 里透明区的 RGB 常是 0,直接透出去会被渲染成黑块);半透明像素的颜色照旧,真正的透明信息在第四通道或「遮罩」端口。
VAE模型COMBO请选择VAE模型编码 Latent 用的 VAE。 • 「请选择VAE模型」= 不使用(不编码 Latent,除非给 VAE 端口连线) • 「使用Josia模型加载VAE」= 直接复用「Josia模型加载」节点已载入的 VAE(需手动选择;不选则不使用模型加载节点的 VAE) • 也可手动从 models/vae 里选一个 • 一旦给「VAE」端口接了线,本项自动灰化 —— 接线优先。
imageCOMBO🖼️请选择或上传图像…从 input 目录选择图像,或点下方「选择要上传的文件」按钮上传。 选中的图像会直接预览在本节点上(与「加载图像」一致)。 默认「🖼️请选择或上传图像…」= 空,节点不产出图像、0.01 秒级快速略过。 「图像」端口接线时本项自动灰化 —— 端口优先。
image_inoptIMAGE—
maskoptMASK—
vaeoptVAE—

Outputs (3)

NameTypeDescription
图像IMAGE—
遮罩MASK—
LatentLATENT—