Operations - Border and Padding

Image Operations / Border and Padding

With the Optidash Image API, you can easily add a border to your images. You may specify border size, color, corner radius, and background color when corner radius is in use. Additionally, you can pad your images to create an empty space around your subject.

Image Border

To add a border to the image, include an additional border hash in your request JSON, which accepts two parameters: size and color.

{
    "border": {
        "size": 10,
        "color": "#ff0000"
    }
}

Border Size and Color

In order to add a border to your images you must, at minimum, provide the border size, which takes a positive integer and describes the thickness of the border, and color parameter, which takes a hex-encoded string in RGB, RRGGBB or AARRGGBB format.

Let's consider a simple example. Suppose you would like to add a gray border (#59646c) of 20px to your images:

{
    "border": {
        "size": 20,
        "color": "#59646c"
    }
}

Image Padding

If you would like to pad your images to create an empty space around your subject, you may provide an additional padding hash with a size parameter, which takes a positive integer. The padded area will, by default, be filled with transparent pixels or solid white color for image formats that do not support alpha-transparency. You can alter this behavior by specifying a background color, which takes a hex-encoded string in RGB, RRGGBB, or RRGGBBAA format.

For example, to pad the image by 40px and set the background color to a semi-transparent blue #126ae750 (in RRGGBBAA format) using PNG as the output format:

{
    "padding": {
        "size": 40,
        "background": "#126ae750"
    },
    "output": {
        "format": "png"
    }
}