Auto Resize & Align
POST
/crop/auto-resize-align
This feature guarantees a polished appearance for a diverse range of products, including shoes, beverages, and home decor, enhancing the overall visual presentation.
Maintaining a consistent eye level significantly improves the browsing experience across various aspect ratios on your online storefront. The Auto Resize & Align API ensures precise alignment and sizing of the focal object, typically a product.
To resize the input image to a 2000x3000 dimension and automatically align the product in the center with uniform 8% margins around it, use the API as follows:
Request
Authorization
Provide your bearer token in the
Authorization
header when making requests to protected resources.Example:
Authorization: Bearer ********************
Body Params application/json
image_url
string <url>
required
.png
, .jpg
, .jpeg
and .webp
, etc. Ensure the URL points directly to a compatible image file.Example:
https://acme.s3.aws.com/image.png
background
string
required
transparent
- Removes the background from the image, allowing for transparency. Note that only PNG
and WebP
file formats support transparent backgrounds. Ensure to specify one of these formats if you opt for a transparent background.white
- Sets the background color to white. This is the default setting, suitable for contexts where a neutral background is preferred.{#hex_code}
- Allows setting the background to any custom color by providing a hex color code. For example, #FF5733
for a vibrant orange background.{image_url}
- Uses an image as the background by specifying its URL. Ensure the URL is accessible and the image format is compatible with your requirements.none
- Keep original background. Note: this option is not supported in all the APIs. Please read the documentation and try the APIs before using them in productions.Note: Please note that the option
none
is only supported in the body-parts
API and not in the auto-resize-align
API.Default:
white
Examples:
transparentwhite#AAAAAAhttp://example.com/background.png
Match pattern:
^(transparent|white|#[0-9A-Fa-f]{6}|https?:\/\/[^\s]+)$
preserve_edge_contact
boolean
optional
Default:
true
output_format
enum<string>
required
Allowed values:
autojpegpngwebp
Default:
auto
Example:
auto
output_dimension
string
Output Dimension
match_to_original
- Keep original image dimension.trim_to_subject
- Keep subject dimensions with all the given margins around it.WidthxHeight
- Resize the image to given width and height. Like 1600x1600Example:
1080x1080
Match pattern:
^(match_to_original|trim_to_subject|(\d{1,4})x(\d{1,4}))$
response_type
enum<string>
required
stream
- The response is streamed back in the same request. This option is optimal for immediate processing or display of the data without the need for a separate download step.url
- The response will be provided as a signed S3 URL. This method will be supported in the future and is ideal for cases where the response needs to be accessed multiple times or shared.Allowed values:
streamurl
Default:
stream
Example:
stream
margins
object (Auto Resize and Align Minimum Margins)
optional
horizontal_alignment
enum<string>
optional
left
, right
, or center
. By default, it is center
.Allowed values:
centerrightleft
Default:
center
Example:
center
horizontal_margin
integer
optional
horizontal_alignment
is set to left
or right
. Specifies the margin as a percentage of the subject's size, controlling the distance from the subject to the selected side. Default value is 0%.>= 0<= 49
Default:
0
vertical_alignment
enum<string>
optional
top
, bottom
, or center
. By default, or if this property is left empty, it is center
.Allowed values:
centertopbottom
Default:
center
Example:
center
vertical_margin
integer
optional
vertical_alignment
is set to top
or bottom
. Specifies the margin as a percentage of the subject's size, controlling the distance from the subject to the selected side. Default value is 0%.>= 0<= 49
Default:
0
minimum_margin
integer
Minimum Margin
>= 1<= 49
Default:
8
Example
{
"image_url": "https://acme.s3.aws.com/image.png",
"background": "white",
"preserve_edge_contact": "true",
"output_format": "auto",
"output_dimension": "1080x1080",
"response_type": "stream",
"margins": {
"horizontal_alignment": "center",
"horizontal_margin": 0,
"vertical_alignment": "center",
"vertical_margin": 0,
"minimum_margin": 8
}
}
Request samples
Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
Request Request Example
Shell
JavaScript
Java
Swift
curl --location --request POST 'https://us1-api.crop.photo/v1/crop/auto-resize-align' \
--header 'Content-Type: application/json' \
--data-raw ''
Responses
🟢200Binary Octel Stream Response
application/octet-stream
Body
object {0}
Example
🟢200Image Crop Response JSON
🟢200Success
🟠401Unauthorized
🟠400Invalid Input | Crop.photo
Modified at 2025-03-17 15:49:11