> ## Documentation Index
> Fetch the complete documentation index at: https://docs.comfy.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Recraft Image Inpainting - ComfyUI ネイティブノードドキュメント

> Recraft API を使用して画像の特定領域を部分的に編集します

<img src="https://mintcdn.com/dripart/5003JSxULDwNImme/images/built-in-nodes/api_nodes/recraft/recraft-image-inpainting.jpg?fit=max&auto=format&n=5003JSxULDwNImme&q=85&s=ce37045a2a53e129f5bec3e425f0002b" alt="ComfyUI ネイティブ Recraft Image Inpainting ノード" width="1731" height="1109" data-path="images/built-in-nodes/api_nodes/recraft/recraft-image-inpainting.jpg" />

Recraft Image Inpainting ノードは、画像の特定領域のみを編集し、残りの部分は変更せずに保持することができます。入力として画像、マスク、およびテキストプロンプトを指定することで、マスクで指定された領域に新しいコンテンツを生成・挿入できます。

## パラメーター

### 基本パラメーター

| パラメーター | 型   | デフォルト | 説明                  |
| ------ | --- | ----- | ------------------- |
| image  | 画像  | -     | 編集対象の入力画像           |
| mask   | マスク | -     | 編集対象領域を定義する白黒マスク    |
| prompt | 文字列 | ""    | マスク領域内に生成するコンテンツの説明 |
| n      | 整数  | 1     | 生成する結果の数（1～6）       |
| seed   | 整数  | 0     | 乱数シード値              |

### オプションパラメーター

| パラメーター            | 型                | 説明                  |
| ----------------- | ---------------- | ------------------- |
| recraft\_style    | Recraft Style    | 生成コンテンツのスタイル設定      |
| negative\_prompt  | 文字列              | 生成コンテンツに含めたくない要素の指定 |
| recraft\_controls | Recraft Controls | 色など、その他の制御オプション     |

### 出力

| 出力    | 型  | 説明       |
| ----- | -- | -------- |
| IMAGE | 画像 | 編集後の画像結果 |

## ソースコード

\[ノードのソースコード（2025-05-03 更新）]

```python theme={null}
class RecraftImageInpaintingNode:
    """
    Modify image based on prompt and mask.
    """

    RETURN_TYPES = (IO.IMAGE,)
    DESCRIPTION = cleandoc(__doc__ or "")  # Handle potential None value
    FUNCTION = "api_call"
    API_NODE = True
    CATEGORY = "api node/image/Recraft"

    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "image": (IO.IMAGE, ),
                "mask": (IO.MASK, ),
                "prompt": (
                    IO.STRING,
                    {
                        "multiline": True,
                        "default": "",
                        "tooltip": "Prompt for the image generation.",
                    },
                ),
                "n": (
                    IO.INT,
                    {
                        "default": 1,
                        "min": 1,
                        "max": 6,
                        "tooltip": "The number of images to generate.",
                    },
                ),
                "seed": (
                    IO.INT,
                    {
                        "default": 0,
                        "min": 0,
                        "max": 0xFFFFFFFFFFFFFFFF,
                        "control_after_generate": True,
                        "tooltip": "Seed to determine if node should re-run; actual results are nondeterministic regardless of seed.",
                    },
                ),
            },
            "optional": {
                "recraft_style": (RecraftIO.STYLEV3,),
                "negative_prompt": (
                    IO.STRING,
                    {
                        "default": "",
                        "forceInput": True,
                        "tooltip": "An optional text description of undesired elements on an image.",
                    },
                ),
            },
            "hidden": {
                "auth_token": "AUTH_TOKEN_COMFY_ORG",
            },
        }

    def api_call(
        self,
        image: torch.Tensor,
        mask: torch.Tensor,
        prompt: str,
        n: int,
        seed,
        auth_token=None,
        recraft_style: RecraftStyle = None,
        negative_prompt: str = None,
        **kwargs,
    ):
        default_style = RecraftStyle(RecraftStyleV3.realistic_image)
        if recraft_style is None:
            recraft_style = default_style

        if not negative_prompt:
            negative_prompt = None

        request = RecraftImageGenerationRequest(
            prompt=prompt,
            negative_prompt=negative_prompt,
            model=RecraftModel.recraftv3,
            n=n,
            style=recraft_style.style,
            substyle=recraft_style.substyle,
            style_id=recraft_style.style_id,
            random_seed=seed,
        )

        # prepare mask tensor
        _, H, W, _ = image.shape
        mask = mask.unsqueeze(-1)
        mask = mask.movedim(-1,1)
        mask = common_upscale(mask, width=W, height=H, upscale_method="nearest-exact", crop="disabled")
        mask = mask.movedim(1,-1)
        mask = (mask > 0.5).float()

        images = []
        total = image.shape[0]
        pbar = ProgressBar(total)
        for i in range(total):
            sub_bytes = handle_recraft_file_request(
                image=image[i],
                mask=mask[i:i+1],
                path="/proxy/recraft/images/inpaint",
                request=request,
                auth_token=auth_token,
            )
            images.append(torch.cat([bytesio_to_image_tensor(x) for x in sub_bytes], dim=0))
            pbar.update(1)

        images_tensor = torch.cat(images, dim=0)
        return (images_tensor, )
```
