Nodes/Kongshan Nodes/CLI 图片输入转临时文件
ComfyUI Node

CLI 图片输入转临时文件

Turn a ComfyUI Image Into a CLI-Ready Prompt + Paths

By kongshan4219·Created 3 months ago·Updated 3 months ago· 0
CLI 图片输入转临时文件
  • image
  • reference_image
  • reference
  • command
  • output_path
  • prompt_path
  • image_path
  • reference_path
command_templateagy --print "Create exactly one final e-commerce product image. Use product image: {image_path}. Use reference image if provided: {reference_path}. Read the detailed design prompt from: {prompt_path}. Save the final image as a PNG file exactly at: {output_path}. After saving, print only the saved image path."
prompt
output_directoryimage_pipeline/antigravity_cli
output_filenameantigravity_result.png
source_image_path

A CLI agent can't see your ComfyUI tensors. It can only see files. KSCLIImageInputFiles is the bridge: it writes your prompt to a temp .txt, your product image to a temp .png, your reference image to another temp .png, then builds a ready-to-run command with real filesystem paths substituted in. Feed its command output to KSAntigravityCLIExecute, and its output_path to KSCLIImageOutputFile to get the result back. It's the "format the inputs for an outside agent" node.

How it works

You give it a command_template containing placeholders, and it replaces them:

  • {prompt_path} - temp file where your prompt text lands (UTF-8, so Chinese prompts survive).
  • {image_path} - temp PNG written from your image tensor.
  • {reference_path} - temp PNG from reference_image, or a path from the reference object; empty string if no reference.
  • {output_dir} and {output_path} - where you expect the agent to save its result.

The default template is a complete Antigravity-style instruction: "Create exactly one final e-commerce product image. Use product image: {image_path}. Read the detailed design prompt from: {prompt_path}. Save the final image as a PNG file exactly at: {output_path}." That's the whole trick - the agent is told exactly which files to read and where to write, so a fallible model still hits the right contract.

The inputs that matter

  • command_template - the big one. Keep the placeholders, and the node handles the paths. This is where you define what the CLI is supposed to do.
  • prompt - the full text written to {prompt_path}. In the intended pipeline this is KSDesignStrategy's final_prompt.
  • image - the product photo tensor.
  • output_directory - default image_pipeline/antigravity_cli. Relative paths land under ComfyUI's output/ dir; absolute paths are used as-is. The 1688-flavored gotcha: leave it blank and connect source_image_path, and it derives a folder named 1688_main next to your source image's white_background folder - pure Alibaba-marketplace workflow logic that only makes sense inside the author's original pipeline.
  • output_filename - default antigravity_result.png. When filled, the node keeps the extension and appends a timestamp, so every run writes a fresh file. When blank + source_image_path, it reuses the source filename with white_background swapped for 1688_main.

Optional: reference_image (direct IMAGE, wins over the object), reference (a KS_REFERENCE), and source_image_path (drives the auto-derivation above).

Outputs: command (the fully-substituted command line), output_path (where the result is expected), plus prompt_path, image_path, reference_path if you want the temp files themselves.

Installing

With the pack:

cd ComfyUI/custom_nodes
git clone https://github.com/kongshan4219/ComfyUI-Kongshan-Nodes

restart ComfyUI. No API key needed - this node only touches local temp files and strings.

Gotchas

  • Temp files accumulate. It writes ks_cli_prompt_<timestamp>.txt etc. into ComfyUI's temp/ dir with no cleanup. Fine for light use; a busy pipeline will litter the temp folder.
  • The output filename changes every run. The timestamp is the point (no clobbering), but it means expected_output_path in the output node is unique per run - which is exactly how KSCLIImageOutputFile knows which file to load, so don't "fix" it.
  • It's built for one specific pipeline. The 1688_main / white_background auto-naming is a clear tell that this is one author's private marketplace workflow open-sourced. It works fine with your own names - just type them into output_directory instead of relying on the blank-path magic.

Young pack, zero impressions everywhere as of now, but the placeholder-substitution pattern here is clean and easy to reuse for any CLI agent, not just Antigravity.

CategoryKongshan/CLI

Inputs (8)

NameTypeDefaultDescription
command_templateSTRINGagy --print "Create exactly one final e-commerce product image. Use product image: {image_path}. Use reference image if provided: {reference_path}. Read the detailed design prompt from: {prompt_path}. Save the final image as a PNG file exactly at: {output_path}. After saving, print only the saved image path."命令模板。可使用 {prompt_path}、{image_path}、{reference_path}、{output_dir}、{output_path} 占位符,节点会替换成实际路径。
promptSTRING写入临时 txt 的完整提示词。外部 CLI 可通过 {prompt_path} 读取。
imageIMAGE写入临时 PNG 的商品图。外部 CLI 可通过 {image_path} 读取。
output_directorySTRINGimage_pipeline/antigravity_cli期望输出目录。相对路径会放在 ComfyUI output 目录下;绝对路径会直接使用。留空且连接 source_image_path 时,保存到 white_background 同级的 1688_main。
output_filenameSTRINGantigravity_result.png期望输出文件名。填写时节点会保留扩展名并追加时间戳;留空且连接 source_image_path 时,使用源图片名并把 white_background 替换为 1688_main。
reference_imageoptIMAGE直接连接的参考图,会写入临时 PNG 并作为 {reference_path}。优先级高于 reference。
referenceoptKS_REFERENCE参考对象。若包含 image 会写入临时 PNG;否则使用其中 path 作为 {reference_path}。
source_image_pathoptSTRING源图片路径。output_directory 留空时用它推导输出目录;output_filename 留空时用源图片名派生输出文件名。

Outputs (5)

NameTypeDescription
commandSTRING
output_pathSTRING
prompt_pathSTRING
image_pathSTRING
reference_pathSTRING