Resize and padding

Image size

Image can be upscaled and placed in any shape/canvas.

It is possible to set just one dimension, the other will be calculated automatically and image ratio will be preserved. Also padding parameter will be used in that case.

Notice that Deep Image supports AI upscale up to 4x of the original resolution. Everything above that will be upscaled traditionally with bicubic supersampling.

Let's check some resize examples.

This is the input image.

The destination image size can be controller with "width" and "height" parameters.

Image can be also upscaled with "print_size" and "dpi" parameters. More on that here in Image Processing / Print chapter.

{
    "url": "https://deep-image.ai/api-example.png",
    "width": 1000,
    "upscale_parameters": {
        "type": "text_x4"
    }
}
curl --request POST \
     --url https://deep-image.ai/rest_api/process_result \
     --header 'content-type: application/json' \
     --header 'x-api-key: API_KEY' \
     --data '{
         "url": "https://deep-image.ai/api-example.png",
         "width": 1000
      }'
{
    "url": "https://deep-image.ai/api-example.png",
    "height": 1000
}
curl --request POST \
     --url https://deep-image.ai/rest_api/process_result \
     --header 'content-type: application/json' \
     --header 'x-api-key: API_KEY' \
     --data '{
         "url": "https://deep-image.ai/api-example.png",
         "height": 1000
      }'

If width and height is specified together, image with original ratio will be upscaled and placed inside "width x height" canvas. Fitting parameter will be used accordingly.

{
    "url": "https://deep-image.ai/api-example.png",
    "width": 1000,
    "height": 1000
}
curl --request POST \
     --url https://deep-image.ai/rest_api/process_result \
     --header 'content-type: application/json' \
     --header 'x-api-key: API_KEY' \
     --data '{
         "url": "https://deep-image.ai/api-example.png",
         "width": 1000,
         "height": 1000
      }'

Fitting and padding

According to specified width and height image can either cropped to fill given canvas or placed fully into the given canvas. When image is cropped checking the image content can be performed.

How the image is placed into destination canvas (with width and height parameters) is controlled by "fit" parameter.

{
    "url": "https://deep-image.ai/api-example.png",
    "width": 1000,
    "height": 1000,
    "fit": "canvas"
}

Types of crop

Image cropping can be performed from the image center or from the center of identified content.

{
    "url": "https://deep-image.ai/api-example2.jpg",
    "width": 1000,
    "height": 1000,
    "fit": {
         "crop": "center"
    }
}

Crop "item" type is not particularly useful without padding and removing background. But it's very useful for "product" type manipulations. More on that at Remove background and item cropping.

Content aware cropping prevents objects being cut by the desired canvas proportions. Let's see some examples.

{
    "width": 1000,
    "height": 1000,
    "fit": "crop"
}

When margin is needed, parameter padding can be used for that. It can be specified either in pixels or in percentages.

{
    "url": "https://deep-image.ai/api-example.jpg",
    "width": 1000,
    "height": 1000,
    "fit": "canvas",
    "padding": "20%"
}

Last updated