POST
/
v1
/
images
/
{image_id}
/
resize
Resize Image
curl --request POST \
  --url https://api.img-processing.com/v1/images/{image_id}/resize \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '{
  "width": 300,
  "height": 200,
  "name": "resized-image",
  "letterbox_color": "transparent",
  "position": "center",
  "fit": "contain"
}'
{
  "id": "image_etm0g3x5iap4cld1qcfsjvo2",
  "name": "Processed Image",
  "url": "https://storage.img-processing.com/images/image_etm0g3x5iap4cld1qcfsjvo2",
  "width": 460,
  "height": 460,
  "format": "jpeg",
  "size": 282000,
  "created_at": "2021-09-01T12:00:00.000Z"
}

Guide

Learn how to resize an image

Description

This endpoint creates a new image by resizing an existing image. At the moment, there are three fit modes available:
Fit Modes

Available fit modes

  • fill: The image is resized to fill the specified dimensions, stretching/squishing the image to fit the provided dimensions. This is the default fit mode.
  • contain: The image is resized to fit within the specified dimensions, maintaining the aspect ratio, and adding a letterbox if necessary.
  • cover: The image is resized to cover the specified dimensions, maintaining the aspect ratio, cropping/clipping the image if necessary.
Additionally, you can specify the background color for the letterbox when using the contain fit mode, and the gravity for cropping or positioning the image when using the cover and contain fit modes. The next image shows the available gravity modes with a white letterbox_color and a contain fit mode:
Gravity Modes

Available gravity modes with a white letterbox_color and a contain fit mode


Authorizations

x-api-key
string
header
required

API Key for authentication

Path Parameters

image_id
string
required

The unique identifier of the image. This identifier is used to reference the image in subsequent requests.

Body

application/json
width
integer

The width of the image to resize. It must be an integer greater than 0 and less than 10000. If not provided, the resized image will keep the aspect ratio of the original image.

Required range: 1 <= x <= 10000
height
integer

The height of the image to resize. It must be an integer greater than 0 and less than 10000. If not provided, the resized image will keep the aspect ratio of the original image.

Required range: 1 <= x <= 10000
name
string

The name of the resized image. It is used to identify the image on the dashboard.

Required string length: 1 - 30
letterbox_color
string

The color of the letterbox when using the contain fit mode. It can be a color name, a hex color code, or transparent.

position
enum<string>

The gravity position of the image when using the cover or contain fit modes.

Available options:
center,
top,
right,
bottom,
left,
top-left,
top-right,
bottom-left,
bottom-right
fit
enum<string>

The fit mode to use when resizing the image.

Available options:
cover,
contain,
fill

Response

The API will return the Image object in the response body.

The Image object represents an image processed using the IMG Processing API. The object contains information about the image, such as its URL, size, and format. The Image object is returned in the response body of all image processing requests.

id
string
required

The unique identifier of the image. This identifier is used to reference the image in subsequent requests.

name
string
required

The name of the image. This name is provided when uploading the image and is the way the image is identified in your account. It is not unique, in fact, each transformation you make to an image will create a new image with the same name.

width
number
required

The width of the image in pixels.

height
number
required

The height of the image in pixels.

format
enum<string>
required

The format of the image. The format can be one of the following: jpeg, png, webp

Available options:
png,
jpeg,
webp
size
number
required

The estimated size of the image in bytes. The size is an estimate and may not be exact since images can be compressed or optimized depending on the format and quality settings used during processing.

created_at
string<date-time>
required

The date and time when the image was created. The date and time are in ISO 8601 format.

url
string | null

The public URL of the image. By default, this URL is not available and will be null. You can make the image public by using the publish endpoint. Once the image is public, the URL will be updated with the public UR.