Nodes/ComfyUI-CraftKit/Smart Batch Resize πŸ“
ComfyUI Node

Smart Batch Resize πŸ“

Point it at a folder, get a training-ready dataset

By CraftopiaStudioΒ·Created 6 months agoΒ·Updated a day agoΒ· 2
Smart Batch Resize πŸ“
    • images
    • count
    β—„input_folderβ–Ί
    β—„longest_side1024β–Ί
    β—„multiple_of8β–Ί
    β—„interpolationlanczosβ–Ί
    β—„upscale_if_smallertrueβ–Ί
    β—„prefixβ–Ί
    β—„use_original_nametrueβ–Ί
    β—„use_counterfalseβ–Ί
    β—„counter_start1β–Ί
    β—„suffix_resolutiontrueβ–Ί
    β—„delimiter_β–Ί
    β—„folder_resolutionfalseβ–Ί
    β—„folder_customresizedβ–Ί
    β—„output_formatkeep_sourceβ–Ί
    β—„alpha_modeautoβ–Ί
    β—„quality95β–Ί
    β—„skip_if_existstrueβ–Ί
    β—„preview_limit32β–Ί

    The part of LoRA training that actually eats your evening isn't the training - it's the prep. You've got 200 high-res images sitting in a folder, and they need to be resized to a consistent longest side, snapped to a multiple of 8, and renamed into something a trainer won't choke on. Smart Batch Resize is the folder β†’ dataset step in one node. Drop it on the canvas, point it at a folder, hit run, and it reads everything, resizes it, and saves the results into a subfolder with clean filenames. No upstream input, no downstream connection, no workflow gymnastics.

    It's part of ComfyUI-CraftKit, a small pack aimed squarely at LoRA dataset pipelines. The rest of the pack (Smart Resize, Smart Resolution Multiplier, the prompt/profile switching pair) covers the generation side; this node is the bulk-preprocessing side.

    How it works

    Under the hood it's Pillow doing Lanczos resizing (bicubic, bilinear, and nearest are there if you want them), preserving aspect ratio by scaling off the longest side, then snapping both dimensions to a multiple - 8 by default, which is what SD/Flux latents want. Nothing fancy, which is the point: it's reliable plumbing, and it has no extra dependencies. Pillow, NumPy and PyTorch all ship with ComfyUI already, so there's no requirements.txt landmine waiting for you.

    The genuinely useful bit is the filename builder. It assembles each output name from the parts you toggle on: a prefix (like headshot), the original filename, a sequential 3-digit counter, and a resolution suffix - joined by a delimiter. So photo_001_1024.jpg isn't hard to get. There's a status label on the node showing the summary, plus a Browse button for the input folder so you're not pasting paths blind.

    The inputs that matter

    You'll touch maybe five of these:

    • Input folder - the source. Use the Browse button. Only files directly in the folder are scanned; subfolders are ignored.
    • Longest side (px) - target for the longest edge, default 1024, with quick presets.
    • Multiple of - 8 for SD/Flux; leave it alone otherwise.
    • Prefix - the label prepended to every filename. This is how you keep categories straight.
    • Use original name / Add counter - at least one of these must be on, or every output would get the same name and the node refuses to run.

    Outputs are images (a list, mainly for previewing in the UI) and count. Both are optional - the node does its job even if you leave them dangling.

    Installing it

    ComfyUI Manager: search for ComfyUI-CraftKit and install. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/CraftopiaStudio/ComfyUI-CraftKit
    

    Then restart ComfyUI. All nodes land under CraftKit in the menu, and because there are no extra dependencies, install is as painless as custom nodes get.

    Where people get burned

    • It's not recursive. Pointing it at a folder full of subfolders silently does nothing to them. Flatten your source first.
    • Output goes inside the input folder, into a resized subfolder by default - the code explicitly refuses to write into the same directory as the originals, so your source is safe, but it does mean running it twice can stack folders.
    • skip_if_exists is smarter than it looks. It only skips a file if the existing output still matches the current settings, so if you lower longest_side on a re-run, stale files get reprocessed instead of silently kept.
    • HEIC and AVIF are on the supported list, but only if your Pillow has the plugins. If not, those files are skipped with a console warning rather than crashing the batch - easy to miss if you're not watching.

    Is it glamorous? No. But it's the kind of node that makes a 200-image dataset prep take one run instead of an hour of manual resizing - and that's the whole job.

    CategoryCraftKit

    Inputs (18)

    NameTypeDefaultDescription
    input_folderSTRINGFolder containing images to resize. Only files directly in this folder are scanned β€” subfolders are not included.
    longest_sideINT102464–8192Longest side target in pixels. Aspect ratio is always preserved.
    multiple_ofINT81–128Snap both dimensions to a multiple of this value. Use 8 for SD/Flux.
    interpolationCOMBOlanczosResampling method. Lanczos is sharpest for downscaling.
    upscale_if_smallerBOOLEANtrueUpscale images that are smaller than the target longest side. Turn off to only ever downscale, never upscale.
    prefixSTRINGLabel prepended to filename. E.g. 'headshot' β†’ headshot_photo_001_1024.jpg
    use_original_nameBOOLEANtrueInclude the original filename in the output name.
    use_counterBOOLEANfalseAdd a sequential 3-digit counter to each filename (001, 002, ...).
    counter_startINT10–99999Starting number for the counter. Useful when processing multiple batches.
    suffix_resolutionBOOLEANtrueAppend resolution to filename. E.g. photo_1024.png
    delimiterSTRING_Separator between filename parts. E.g. _ or -
    folder_resolutionBOOLEANfalseAppend resolution to subfolder name. E.g. resized_1024
    folder_customSTRINGresizedSubfolder name. Resolution is appended if 'Create resolution subfolder' is on.
    output_formatCOMBOkeep_sourceFile format for saved images. 'keep_source' preserves each file's original extension. jpg cannot store transparency.
    alpha_modeCOMBOautoauto: preserve transparency only if the source has it. flatten: always composite onto white and output opaque RGB. keep: always output RGBA. jpg/bmp output always flattens regardless (those formats can't store alpha).
    qualityINT951–100Compression quality for jpg/webp output. Ignored for png (always lossless).
    skip_if_existsBOOLEANtrueSkip files that already exist in the output folder AND still match the current size settings. If longest_side/multiple_of/upscale_if_smaller changed since the file was made, it's reprocessed instead of skipped.
    preview_limitINT320–10000Max images to keep in memory for the preview output. All files are still processed and saved to disk; this only limits what's returned/previewed. 0 = no limit.

    Outputs (2)

    NameTypeDescription
    imagesIMAGEβ€”
    countINTβ€”