Any Image → Any Aspect Ratio
Upload any image and input your desired aspect ratio. Generate an outpainted version of your image to perfectly fit the new dimensions.
概要
This ComfyUI workflow is designed to transform any image into a new aspect ratio by utilizing advanced outpainting techniques. At its core, the workflow leverages the Nano Banana 2 model, known for its robust image completion capabilities. The process begins by uploading an image and specifying the desired aspect ratio, such as 16:9, 9:16, 1:1, or 4:5.
The workflow then adapts the original image to fit the new dimensions, filling in the additional space with content that seamlessly extends the image's natural environment. This is achieved through a series of nodes, including LoadImage for importing the image, ImageCompositeMasked for handling the outpainting, and PreviewImage for visualizing the results.
What makes this workflow particularly useful is its ability to maintain the visual integrity of the original image while expanding its dimensions. This is ideal for content creators who need to adapt images for various platforms with different aspect ratio requirements. The integration of custom nodes like comfyui_essentials, controlaltai-nodes, and masquerade-nodes-comfyui further enhances the workflow's flexibility and precision, ensuring high-quality outputs that are both aesthetically pleasing and contextually relevant.
入力するもの
- ワークフローを読み込み中
ComfyUI で実行できます。 このワークフローはこのページでは実行できません。すべてが読み込まれた状態でComfy Cloudで開くか、ご自身のComfyUI用にダウンロードしてください。
Cloudで試すワークフローの内部
ノードグラフの読み取り専用プレビューです。ノードを編集するには、Comfy Cloudで開くかダウンロードしてください。
Loading the graph
Open full-size workflow preview- 作成者
- ComfyUI
カスタムノードが必要です
- ワークフローを読み込み中
コードからこのワークフローを使用する
可能な場合はワークフローグラフと入力から生成されます。それ以外の場合は保存された例が表示されます。料金が発生する場合があるため、コードを実行する前に認証情報とエンドポイントを確認してください。
What you need
- Runs on
- Comfy Cloud
- キー
- COMFY_API_KEY
有料の Cloud プランとクレジットが必要です。
# Python 3.10+: pip install comfy-sdk==0.4.0
import os
from comfy_sdk import Comfy
api_key = os.environ.get("COMFY_API_KEY", "").strip()
if not api_key: raise RuntimeError("Set COMFY_API_KEY")
os.environ.setdefault("COMFY_BASE_URL", "https://cloud.comfy.org")
client = Comfy(api_key=api_key)
workflow = client.workflows.from_json({
"130": {
"class_type": "LoadImage",
"inputs": {
"image": "input-aspect-ratio-converter"
},
"_meta": {
"title": "Load Image"
}
},
"144": {
"class_type": "ImageCompositeMasked",
"inputs": {
"destination": [
"224:162",
0
],
"mask": [
"224:168",
0
],
"resize_source": True,
"source": [
"225",
0
],
"x": 0,
"y": 0
},
"_meta": {
"title": "Image Composite Masked"
}
},
"218": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"144",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"225": {
"class_type": "GeminiNanoBanana2",
"inputs": {
"aspect_ratio": "auto",
"images": [
"224:162",
0
],
"model": "Nano Banana 2 (Gemini 3.1 Flash Image)",
"prompt": "fill white areas. retain composition.",
"resolution": "4K",
"response_modalities": "IMAGE",
"seed": 592182428395941,
"system_prompt": "You are an expert image-generation engine. You must ALWAYS produce an image.\nInterpret all user input—regardless of format, intent, or abstraction—as literal visual directives for image composition.\nIf a prompt is conversational or lacks specific visual details, you must creatively invent a concrete visual scenario that depicts the concept.\nPrioritize generating the visual representation above any text, formatting, or conversational requests.",
"thinking_level": "HIGH"
},
"_meta": {
"title": "Nano Banana 2"
}
},
"226": {
"class_type": "PreviewImage",
"inputs": {
"images": [
"224:162",
0
]
},
"_meta": {
"title": "Preview Image"
}
},
"224:152": {
"class_type": "Paste By Mask",
"inputs": {
"image_base": [
"224:230",
0
],
"image_to_paste": [
"224:229",
0
],
"mask": [
"224:229",
0
],
"resize_behavior": "keep_ratio_fit"
},
"_meta": {
"title": "Paste By Mask"
}
},
"224:153": {
"class_type": "ImageToMask",
"inputs": {
"channel": "red",
"image": [
"224:152",
0
]
},
"_meta": {
"title": "Convert Image to Mask"
}
},
"224:158": {
"class_type": "ImageToMask",
"inputs": {
"channel": "red",
"image": [
"224:231",
0
]
},
"_meta": {
"title": "Convert Image to Mask"
}
},
"224:159": {
"class_type": "InvertMask",
"inputs": {
"mask": [
"224:153",
0
]
},
"_meta": {
"title": "Invert Mask"
}
},
"224:162": {
"class_type": "ImageRemoveAlpha+",
"inputs": {
"image": [
"224:165",
0
]
},
"_meta": {
"title": "🔧 Image Remove Alpha"
}
},
"224:163": {
"class_type": "Get Image Size",
"inputs": {
"image": [
"130",
0
]
},
"_meta": {
"title": "Get Image Size"
}
},
"224:165": {
"class_type": "Paste By Mask",
"inputs": {
"image_base": [
"224:231",
0
],
"image_to_paste": [
"130",
0
],
"mask": [
"224:152",
0
],
"resize_behavior": "keep_ratio_fit"
},
"_meta": {
"title": "Paste By Mask"
}
},
"224:168": {
"class_type": "MaskComposite",
"inputs": {
"destination": [
"224:158",
0
],
"operation": "add",
"source": [
"224:159",
0
],
"x": 0,
"y": 0
},
"_meta": {
"title": "Combine Masks"
}
},
"224:191": {
"class_type": "FluxResolutionNode",
"inputs": {
"aspect_ratio": "9:16 (Slim Vertical)",
"custom_aspect_ratio": "1:1",
"custom_ratio": False,
"divisible_by": "8",
"megapixel": "2.1"
},
"_meta": {
"title": "Flux Resolution Calc"
}
},
"224:229": {
"class_type": "LayerUtility: ColorImage V2",
"inputs": {
"color": "#ffffff",
"custom_height": [
"224:163",
1
],
"custom_width": [
"224:163",
0
],
"size": "custom"
},
"_meta": {
"title": "LayerUtility: ColorImage V2"
}
},
"224:230": {
"class_type": "LayerUtility: ColorImage V2",
"inputs": {
"color": "#000000",
"custom_height": [
"224:191",
1
],
"custom_width": [
"224:191",
0
],
"size": "custom"
},
"_meta": {
"title": "LayerUtility: ColorImage V2"
}
},
"224:231": {
"class_type": "LayerUtility: ColorImage V2",
"inputs": {
"color": "#ffffff",
"custom_height": [
"224:191",
1
],
"custom_width": [
"224:191",
0
],
"size": "custom"
},
"_meta": {
"title": "LayerUtility: ColorImage V2"
}
}
})
# run() also passes api_key to the partner nodes in this workflow.
job = client.run(workflow, api_key=api_key)よくある質問
Yes, the workflow supports most common image formats, including JPEG, PNG, and BMP.
The Nano Banana 2 model is designed to blend seamlessly, but you can adjust parameters or manually refine the output if needed.
Yes, you can always reload the original image and start the process again if you're not satisfied with the results.
While the workflow can manage a wide range of aspect ratios, extremely disproportionate dimensions may require additional manual adjustments for optimal results.