API Documentation
  • Welcome!
  • Quick Start
  • API methods
  • Easy integration
  • Handling Large File Sets
  • Supported formats
  • Webhooks
  • Common usecases
    • Auto enhance image quality
    • Create business photo or avatar from face image
    • Face swap
    • Create beautiful product photo
    • Genarate image in high resolution
    • Remove background
    • AI Drawing to Image - Doodle
    • Real estate
    • Enhancing documents
    • Car dealer photo
  • Image processing
    • Resize and padding
    • Denoise and sharpen
    • Enhance lighting and colors
    • Enhance face details
    • Background removal and generation
    • Image generation
    • Inpainting and outpainting (uncrop)
    • Frame identification
    • Print
    • Captions
    • Additional parameters
    • Presets
  • Account & settings
    • Account information
  • storages
    • Description
    • AWS S3
    • AWS S3 IAM Configuration
  • Presets
    • E-commerce
    • Real-estate
    • Print/Photo
    • Digital Art
  • Technology
    • Algorithms
    • Upscale
    • Background removal
      • Remove BG recommendation
    • Sharpen & Noise reduction
    • Enhance Lighting
  • FAQ
Powered by GitBook
On this page
  • Image size
  • Fitting and padding
  • Types of crop
  1. Image processing

Resize and padding

PreviousCar dealer photoNextDenoise and sharpen

Last updated 5 months ago

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.

Parameter name
Description

width

  • string f.e. - "200%" - it will upscale image by factor 2.

  • integer f.e. - 200 - it will upscale/downscale image to have width 200 pixels. If the height is not given it will be calculated to match image ratio.

height

  • string f.e. - "200%" - it will upscale image by factor 2.

  • integer f.e. - 200 - it will upscale/downscale image to have height 200 pixels. If the width is not given it will be calculated to match image ratio.

min_length

integer f.e. - 200 - it will upscale/downscale image to have minimum 200 pixels width or height. That will also be applied to identified item/content when removing background.

generative_upscale

upscale_parameters: type

  • v1 - (default) - basic AI upscaling method

  • text_x4 - used to upscale images containing text, such as invoices or product photos with labels, optimizing clarity and readability of the text.

{
    "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
      }'
import os

import deep_image_ai_client

configuration = deep_image_ai_client.Configuration(
    host="https://deep-image.ai"
)

configuration.api_key['ApiKeyAuth'] = os.environ["API_KEY"]

with deep_image_ai_client.ApiClient(configuration) as api_client:
    api_instance = deep_image_ai_client.DefaultApi(api_client)
    process_payload = {"url": "https://deep-image.ai/api-example.jpg", "width": 1000}
    api_response = api_instance.rest_api_process_result_post(process_payload)
{
    "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
      }'
import os

import deep_image_ai_client

configuration = deep_image_ai_client.Configuration(
    host="https://deep-image.ai"
)

configuration.api_key['ApiKeyAuth'] = os.environ["API_KEY"]

with deep_image_ai_client.ApiClient(configuration) as api_client:
    api_instance = deep_image_ai_client.DefaultApi(api_client)
    process_payload = {"url": "https://deep-image.ai/api-example.jpg", "height": 1000}
    api_response = api_instance.rest_api_process_result_post(process_payload)

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
      }'
import os

import deep_image_ai_client

configuration = deep_image_ai_client.Configuration(
    host="https://deep-image.ai"
)

configuration.api_key['ApiKeyAuth'] = os.environ["API_KEY"]

with deep_image_ai_client.ApiClient(configuration) as api_client:
    api_instance = deep_image_ai_client.DefaultApi(api_client)
    process_payload = {"url": "https://deep-image.ai/api-example.jpg", "width": 1000, "height": 1000}
    api_response = api_instance.rest_api_process_result_post(process_payload)

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.

Name
Description

canvas

crop

Image is cropped to match destination width x height canvas. Crop is content aware by default. It can be changed to be on center as well.

bounds

image is upscaled to fit specified width x height.

cover

image is upscaled to fully cover specified width x height.

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

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"
    }
}
{
    "url": "https://deep-image.ai/api-example2.jpg",
    "width": 1000,
    "height": 1000,
    "fit": {
         "crop": "content"
    }
}

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

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%"
}
{
    "url": "https://deep-image.ai/api-example.jpg",
    "width": 1000,
    "height": 1000,
    "fit": "crop",
    "padding": "20%"
}

true/false - Turns on upscaling based on diffusion algorithms. Image is generated max in 2048x2048 resolution and then upscaled further using standard AI upscaling. More on that:

(default) - whole image is placed into width x height canvas, missing space is filled with background color. Additionally "outpainting" might be specified - more on that

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 .

https://documentation.deep-image.ai/image-processing/image-generation#generative-upscaling
Remove background and item cropping
here
Input image: 640x427
Result image: 1000x667
Result image: 1500x1000
Result image: 1000x1000
Result image: 1000x1000
Result image: 1000x1000
Input
Result
Result
Input image
Result image: 1000x1000, content: 800x533, padding 200 pixels
Result image: 1000x1000, content: 800x800, padding: 200