Search…
Padding
Sometimes there is a need to add a space around the object to meet task requirements. A handy example is eCommerce where the frame around the goods is essential for a visual experience, and when you start moving with the solution you understand how tricky it is to get right and these become exponentially challenging considering how different eCommerce platforms have specific standards and requirements for product photos.
With Claid API you can control the surrounding space using padding operation, where you can pass a value as a percentage or multiple values for both dimensions. The padding cannot be more than half the width/height.
Examples: "10%","30%","5% 25%".
Let's explore the simple example where we just need to add padding around the picture:
1
{
2
"input": "https://staging.claid.ai/assets/cms/shoe_example_05fb154a3a/shoe_example_05fb154a3a.png",
3
"operations": {
4
"padding": "30%"
5
}
6
}
Copied!
Before adding padding
After adding padding
In this request, Claid preserves the actual image size, hence squeezing the image and filling the surrounding space with the padding.
But let's consider more use cases.
Background Removal
Safe Zones
Most eCommerce platforms will require photos to have a white background. Claid has a feature that automatically crops out the product image and leaves the background entirely white.
But it's not enough just to remove the background because the resulting object will be fit to borders. Controlling the empty space surrounding the product image would add a more natural look and help meet platform requirements.
Let's assume that we need to remove the background and specify the intensity of the surrounding space:
1
{
2
"input": "https://staging.claid.ai/static/0190d55e7097dfad9239168a5cc2cfae/36f6d/E_com_Input_Enhancement_AI_Color_3e806177ae.webp",
3
"operations": {
4
"background": {
5
"remove": {
6
"clipping": true
7
}
8
},
9
"padding": "20%"
10
}
11
}
Copied!
Before adding padding
After adding padding
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.
Also, you can control the color of the background, please see the Background section.
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.
Squeezed images on different pages
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:
1
{
2
"input": "https://staging.claid.ai/ecommerce-images/safe-zones/",
3
"operations": {
4
"resizing": {
5
"fit": "canvas",
6
"width": 1600,
7
"height": 900,
8
},
9
"background": {
10
"remove": {
11
"clipping": true
12
}
13
},
14
"padding": "10% 25%"
15
}
16
}
Copied!
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%"
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.
Copy link
Edit on GitHub