Nodes/comfyui-ayang_node/Canvas Size Crop for Img2Img
ComfyUI Node

Canvas Size Crop for Img2Img

A White Canvas That Quietly Sets Your Img2Img Size

By AICGayang·Created 12 months ago·Updated 12 months ago· 42
Canvas Size Crop for Img2Img
    • image
    canvas_preset1:1 - 1024x1024

    This node does one small job, and it does it by producing a blank white rectangle. Display name "Canvas Size Crop for Img2Img", class nanobanana 图生图尺寸调整 - it's the companion utility to the AICG Ayang Image-to-Image node in the same pack, and it exists for a reason that isn't obvious until you hit it.

    Here's the situation. The img2img node in this pack is an API wrapper: it sends your image and prompt to a hosted model over OpenRouter and gets an image back. Hosted models don't read your ComfyUI canvas. There's no EmptyLatentImage to hang a resolution on, so the pack controls output size the only way it can - by telling the model what size to draw, and by giving it a reference image at the right dimensions to match. This node is the reference-image half of that trick: a clean canvas already cropped to a preset aspect ratio that you wire in as the size anchor.

    Mechanism is almost laughably simple (the source is ~60 lines). It builds a 2048×2048 pure-white RGB canvas with Pillow and center-crops it to whatever preset you pick. Because it's solid white, nothing is lost in the crop - effectively you get a blank canvas at exactly the target size, returned as a standard IMAGE tensor.

    The one input that matters is canvas_preset, an 8-choice dropdown covering the standard ComfyUI ladder:

    • 1:1 - 1024x1024, 3:4 - 896x1152, 5:8 - 832x1216, 9:16 - 768x1344
    • 9:21 - 640x1536, 4:3 - 1152x896, 3:2 - 1216x832, 16:9 - 1344x768

    Output is a single image (IMAGE). Wire it into the AICG Ayang Image-to-Image node's image input (or any img2img workflow that accepts a reference canvas), prompt as usual, and run.

    Install it the same way you install the whole pack - you're not going to install this node by itself:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AICGayang/comfyui-ayang_node
    cd comfyui-ayang_node
    pip install -r requirements.txt
    

    Then restart ComfyUI. ComfyUI Manager users can just search "comfyui-ayang_node" and skip the terminal. Dependencies are light - gradio, Pillow, openpyxl, openai, requests - no model downloads, no VRAM.

    Where people get tripped up: remember this node returns a blank image. If you stare at the output and wonder where your content is, that's not a bug, that's the whole point - it's a canvas for the model to match, not a generation. And set expectations on the sizing itself. The pack's img2img node appends "please output the final image at exactly WxH" to your prompt, and cloud image models (especially the Gemini/Nano Banana lineage this pack targets) will often pick their own preferred aspect anyway. The canvas is a strong hint, not a contract. If your output comes back at the wrong size, that's the model ignoring the instruction, not this node misbehaving - and if the node itself ever errors, it quietly falls back to a default 1024×1024 white image, which is another reason to verify the size you actually got.

    CategoryAICG Ayang

    Inputs (1)

    NameTypeDefaultDescription
    canvas_presetoptCOMBO1:1 - 1024x10248 options: 1:1 - 1024x1024, 3:4 - 896x1152, 5:8 - 832x1216, 9:16 - 768x1344, 9:21 - 640x1536, 4:3 - 1152x896, +2

    Outputs (1)

    NameTypeDescription
    imageIMAGE