Generate Images Using Canvas Inpainting

This feature allows for uploaded or generated Images as reference, apply ControlNet and add finer adjustments to your image appearance.

Follow this recipes with code snippets to generate images using Canvas Inpainting

Inpainting

This guide will recreate the following Canvas Inpainting functionality in the Web UI via API.

Generation using multiple Style Reference

Inpainting Feature in Canvas Editor on web

Generated Inpaint Image

Generated Inpaint Image

Canvas Parameter Breakdown

  • Image dimensions for images uploaded to canvasInitId and canvasMaskId must be divisible by 8.
  • Ensure canvasRequest is set to True when using Canvas Editor features.
  • Models can be specified using modelId. All models except for Leonardo Lightning XL, Leonardo Anime XL and Phoenix can be used with Canvas Inpainting. A list of model Ids can be found here
  • Inpaint Strength is init_strength, which must be subtracted from 1 to match the equivalent value. E.g. In the example above, the Inpaint strength is 0.85, which equates to init_strength:0.15.
  • Max Inpaint strength is init_strenght:0.8.
  • Default values for num_images is 4, init_strength is 0,guidance_scale is 7.
  • Accepted file formats are jpg, png, jpeg, webp.

Uploading Mask

πŸ“˜

Note

  • Masks must be uploaded as a white element against a black background. Inpainting will be applied on the white area.
  • Additional colour can be applied on the init image.
  • Mask and Init Image dimensions must match, otherwise image generation will fail.
Mask image upload as a white area on black background to apply Canvas Inpainting

Mask image upload as a white area on black background to apply Canvas Inpainting


Image Dimension Generation Limit

Max height and width dimensions for both canvasInitId and canvasMaskIdis 1536x1536. This table shows the allowed number of images based on the image dimension of the init and mask image.

Dimensionsnum_images
512x5128
768x7688
512x10244
768x10244
> 1024x10242

Sample Request

🚧

Parameter compatibility

Parameters other than those listed below are not compatible with Canvas Inpainting, i.e. alchemy, photoReal.

curl --request POST \
     --url https://cloud.leonardo.ai/api/rest/v1/generations \
     --header 'accept: application/json' \
     --header 'authorization: Bearer <YOUR_API_KEY>' \
     --header 'content-type: application/json' \
     --data '
{
    "prompt": "a bright sun",
    "canvasRequest": True,
    "num_images": 4,
    "init_strength": 0.15, // Inpaint strength 0.85
    "canvasRequestType": "INPAINT",
    "guidance_scale": 7,
    "modelId": "1e60896f-3c26-4296-8ecc-53e2afecc132",  // Leonardo Diffusion XL
    "canvasInitId": init_image_id,
    "canvasMaskId": masks_image_id
}