Nodes/ComfyUI-ZhiHui/🖼️ 智绘_纯净图片加载器
ComfyUI Node

🖼️ 智绘_纯净图片加载器

Stretch, crop, or pad

By zhuyungen·Created 8 months ago·Updated 4 months ago· 0
🖼️ 智绘_纯净图片加载器
    • images
    • filename_text
    • directory
    ◄directory_path►
    ◄start_index0►
    ◄batch_size1►
    ◄load_modeIndex (按顺序)►
    ◄seed0►
    ◄resize_modePad (填充-推荐)►
    ◄target_width0►
    ◄target_height0►

    The pack's other folder loader (ZH_BatchImageLoader) will error out the moment your batch mixes a 1024×1024 and a 512×2048. This one, ZH_ImageBatchLoader (🖼️ 智绘_纯净图片加载器), is the one that doesn't care. It loads a slice of a folder into a uniform batch and, crucially, has an explicit answer to the mixed-size problem - stretch, crop, or pad - plus a stateless index system that makes chunked batch runs predictable. "纯净" (pure/clean) in the name refers to that statelessness: no hidden memory of what you loaded last time, every run starts from the index you say.

    How it works

    Point it at directory_path, and it lists the image files, sorts them, and loads batch_size images starting at start_index. The load_mode dropdown flips between Index (按顺序) and Random (随机抽取) - and unlike the pack's other loader, this one has a seed input, so random mode is reproducible. The signature feature is resize_mode:

    • Disabled (报错) - no resizing; heterogeneous sizes fail loudly (that's the "报错" = error in the label). For when you want to be told about mismatches.
    • Stretch (拉伸) - force everything to target size, aspect ratio be damned. Fast, ugly.
    • Crop (裁剪) - scale-to-fill then center-crop, preserving aspect ratio but losing edges.
    • Pad (填充-推荐) - scale-to-fit into the target canvas and letterbox the rest. The recommended default, because nothing gets cut off and the aspect ratio survives.

    target_width and target_height default to 0 = follow the first image (the tooltips say it plainly), so you only set explicit sizes when you want a fixed canvas. It uses Pillow's ImageOps under the hood for the resize/pad logic.

    The inputs that matter

    • directory_path - where the images live.
    • resize_mode - set this to Pad (填充-推荐) and you can throw any folder at it without thinking about dimensions.
    • start_index + batch_size - your chunking pair for processing big folders across runs.
    • seed - makes Random mode reproducible; 0 is still random, same house convention.

    Outputs: images (IMAGE) batch, filename_text (STRING), and directory (STRING) - a convenient passthrough of the folder path for downstream save nodes.

    Install

    Part of the 智绘灵箱 (ComfyUI-ZhiHui) pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/zhuyungen/ComfyUI-ZhiHui.git
    

    Restart ComfyUI (or ComfyUI Manager, "智绘灵箱" / "ComfyUI-ZhiHui"). Pillow-only at runtime.

    Where people get burned

    • Pad keeps everything but adds bars. If your downstream expects edge-to-edge content, padded letterbox bars will surprise you. That's what Crop is for.
    • Batch must still be uniform. Pad makes it uniform by construction, but if you leave resize_mode on Disabled and feed mixed sizes, you get an error - which is the feature working as intended, not a bug.
    • Two loaders in one pack, easily swapped by accident. ZH_BatchImageLoader scans recursively with a 1000-cap; this one slices by index with a 100-max batch. If your workflow "mysteriously" stops loading, check which one you wired.
    • 0 = follow first image means order matters. Sort order decides the reference dimensions, so with alphabetical load the first file defines the canvas. Fine 99% of the time; just don't assume the biggest file sets it.

    This is the loader I'd pick for any folder where the source images aren't already uniformly sized - which, let's be honest, is every real folder. Set Pad, set batch size, go.

    Category智绘灵箱/图片

    Inputs (8)

    NameTypeDefaultDescription
    directory_pathSTRING—
    start_indexINT00–100000—
    batch_sizeINT11–100—
    load_modeCOMBOIndex (按顺序)2 options: Index (按顺序), Random (随机抽取)
    seedINT00–18446744073709550000—
    resize_modeCOMBOPad (填充-推荐)4 options: Disabled (报错), Stretch (拉伸), Crop (裁剪), Pad (填充-推荐)
    target_widthINT00–40960 = 跟随第一张图
    target_heightINT00–40960 = 跟随第一张图

    Outputs (3)

    NameTypeDescription
    imagesIMAGE—
    filename_textSTRING—
    directorySTRING—