LogoLogo
  • Overview
  • Quick Start
  • Authentication
  • Rate limits
  • Errors
  • Image Editing API
    • Image I/O
    • Image Operations
      • Restorations
      • Resizing
      • Outpainting
      • Generative Editing
      • Color Adjustments
      • Background
      • Padding
      • Privacy
    • API Reference
    • Async API Reference
    • Batch API Reference
    • Upload API Reference
  • image generation api
    • Image Generation I/O
    • Image Generation Options
    • API Reference
  • AI Background API
    • AI Background I/O
    • AI Background Options
      • Object
      • Scene
      • Product Shadow
    • API Reference
  • Image to Video API
    • Image to Video I/O
    • Image to Video Options
    • Async API Reference
  • Storage Connectors
    • Overview
    • AWS S3
    • Google Cloud Storage
    • Web Folder
    • API Reference
  • Guides
    • E-commerce
    • Real Estate
    • Printing
  • Redoc
  • Blog
Powered by GitBook
On this page
  • Padding in percentage
  • Padding in pixels
Edit on GitHub
  1. Image Editing API
  2. Image Operations

Padding

PreviousBackgroundNextPrivacy

Last updated 7 months ago

With Claid you can control how much space there's around the object. padding allows you to achieve a consistent look for visuals across your platform. This is an essential operation for eCommerce where the frame around the goods is essential for a visual experience.

There are two main ways to control padding in the Claid API: as a percentage or in pixels.

Value
Type
Description

"10%", or

"5% 15%"

string

Fills the space relative to the total image size, preserving the actual image size. Can be specified:

  • A single value for all sides.

  • Two values for the horizontal and vertical sides.

The padding cannot be more than half the width/height.

"30px", or

"100px 150px", or

"0px 400px 0px 0px"

string

Fills the space with the exact number of pixels. Can be specified:

  • As a single value for all sides.

  • Two values for the horizontal and vertical sides.

  • Four values for the top, bottom, left, and right sides.

The padding for each side of the image can't exceed 4096px.

Let's explore the simple example where we just need to add padding around the picture:

{
  "input": "https://claid.ai/assets/cms/shoe_example_05fb154a3a/shoe_example_05fb154a3a.png",
  "operations": {
     "padding": "30%"
  }
}

In this request, Claid preserves the actual image size, hence squeezing the image and filling the surrounding space with padding.

But let's consider more use cases.

Padding in percentage

But it's not enough just to remove the background because the resulting object will be trimmed to borders. Controlling the empty space surrounding the product image would add a more natural look and help meet the platform's requirements.

Let's assume that we need to remove the background and specify the amount of the surrounding space:

{
  "input": "https://claid.ai/static/0190d55e7097dfad9239168a5cc2cfae/36f6d/E_com_Input_Enhancement_AI_Color_3e806177ae.webp",
  "operations": {
    "background": { 
      "remove": { 
        "clipping": true 
      }
    },
    "padding": "20%"
  }
}

We specify the clipping background removal operation to crop the background up to the foreground object, so the start of padding will be counted from the borders of the object.

If the output sizes are not specified, Claid uses the source width and height, squeezing the shoe to satisfy the padding value.

An image can be shown to users on different pages squeezed with different dimensions. In general, objects are still visible after image transformations, but non-standard borders can be dropped from the visible area.

With Claid, you can specify the Safe Zone for objects, setting up the padding from horizontal and vertical sides as the minimum borders. You can enumerate horizontal and vertical paddings via a space separator, e.g. "10% 25%".

Let's explore an example of the resized image with removed background and compare the result with and without safe zones:

{
  "input": "https://claid.ai/ecommerce-images/safe-zones/",
  "operations": {
    "resizing": { 
      "fit": "canvas",
      "width": 1600,
      "height": 900,
    },
    "background": { 
      "remove": { 
        "clipping": true 
      }
    },
    "padding": "10% 25%"
  }
}

We see that Claid uses our sizes and adjusts the object largeness to fit the required padding value.

On the left side, we can observe the image that would not be correctly shown on a preview page due to the one-side padding. It's better to specify padding for both sides so the image would definitely fit on different pages as shown on the image on the right side.

Please note that Claid automatically detects and customizes the smaller side padding to meet the required dimensions.

Padding in pixels

Padding in pixels is used in the same cases as Padding in percentage, but allows for more granular control over the surrounding space.

Suppose you need to remove the background and fix the product to the top. In this case, specifying padding on all sides will give the most accurate result.

{  
  "input": "https://claid.ai/static/0190d55e7097dfad9239168a5cc2cfae/36f6d/E_com_Input_Enhancement_AI_Color_3e806177ae.webp",
  "operations": {
    "background": { 
      "remove": { 
        "clipping": true 
      }
    },
    "resizing": {
      "width": 2048,
      "height": 2048,
      "fit": "canvas"
    },
    "padding": "0px 500px 0px 0px"
  }
}

Most eCommerce platforms will require photos to have a white background. Claid has a feature that automatically and leaves the background entirely white.

Also, you can control the color of the background, please see the .

Be careful when choosing a , as the canvas fit additionally fill the padding space to respect the aspect ratio.

crops out the product image
Background section
Squeezed images on different pages
An example image
The square frame on top of the processed image without safe zones, padding is "10%
The square frame on top of the processed image with safe zones, padding is "10% 25%"
#fit