Auto Resize & Align
POST
/crop/auto-resize-alignAuto resize and align in Crop.photo, seamlessly resize and align your products within the frame while replacing the background with given color or background image.
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.
Example 1:
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:
curl --location 'https://us1-api.crop.photo/v1/crop/auto-resize-align' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json'
--header 'Authorization: Bearer :XXX-XXXX-API-KEY' \
--data '{
"image_url": "https://images.unsplash.com/photo-1599382266831-50a19097d81d?w=800&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTB8fHJveWFsJTIwZW5maWVsZHxlbnwwfHwwfHx8MA%3D%3D",
"background": "#FFFFFF",
"preserve_edge_contact": true,
"output_format": "jpeg",
"output_dimension": "2000x3000",
"response_type": "url",
"margins": {
"minimum_margin": 8
}
}'
Request
- Specifies the URL of the image. The URL should be a direct link to the image file, allowing the system to retrieve and process the image as needed.
- The URL must be publicly accessible to ensure the system can retrieve the image without authentication barriers.
- Supported image formats include
.png
,.jpg
,.jpeg
and.webp
, etc. Ensure the URL points directly to a compatible image file. - Use a reliable hosting service to prevent issues with image availability or loading times.
- This property is essential for operations that require an image as input, facilitating the integration of external images into the workflow.
Determines the background setting for the image. The options include:
transparent
- Removes the background from the image, allowing for transparency. Note that onlyPNG
andWebP
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.
Some subjects are attached to edges. Keep it or remove it to control alignment.
Pick the perfect image format for your cropped images based on your unique needs.
Possible values are:
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 1600x1600
- Specifies the method by which the response is delivered to the client. Available options include:
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.- Note: Choosing the appropriate response type depends on the use case and the desired workflow for accessing the response data.
Specifies the horizontal alignment of the subject. Options are left
, right
, or center
. By default, it is center
.
Applicable only when 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%.
Specifies the vertical alignment of the subject. Options are top
, bottom
, or center
. By default, or if this property is left empty, it is center
.
Applicable only when 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%.
Defines the minimum margin around the subject as a percentage of the subject's size. This margin is always applied to all sides, ensuring the subject is not too close to any edge. Applies even if other margins are set to 0%.
{
"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
Responses
Binary image data