Change Background of Images API

2000 atoms
Premium tier

About

This API lets you change the background of images. The API accepts input images in multiple formats, including WebP, JPG, JPEG, PNG, BMP, GIF, and TIFF.
The API is ideal for applications in e-commerce that include some kind of photo editing and/or graphic design. Whether you are a content creator or own a user-facing app or website you can work to connect this API and simplify your workflow in minutes.
Try out the API in the API playground and see how this free image background API can help you save time and reduce image editing errors through a simple API call.
Select API Endpoints
Input
Output

API Playground

API Documentation

input file: output file
POST
https://api.apyhub.com/processor/image/change-background/file

Request example

1
curl --location --request POST 'https://api.apyhub.com/processor/image/change-background/file?output=test-sample.png' \
2
--header 'apy-token: {{token}}' \
3
--form 'image=@"stock-photo.jpg"' \
4
--form 'background_image=@"stock-photo.jpg"'
Method: POST
Content Type: multipart/form-data
Query Parameter(s)
AttributeTypeMandatoryDescription
outputStringNoThe output file name for the image.
Request Body
AttributeTypeMandatoryDescription
imageFileYesthe source image file
background_colorStringYes (if background_image not given)the background color for the image, should be in hexadecimal color#rrggbb format. For example #000000 for white. If background_color and background_image both are present in the request then background_color will be applied.
background_imageFileYes (if background_color not given)the path of background image file which should be accessible by ApyHub. If background_color and background_image both are present in the request then background_color will be applied.
image_positionStringNothe image position. For example: you want to add the image at center position then it will be as image_position: bottom_right and it defaults to center and user can enter any of top_right,top_left,bottom_right,bottom_left,center
image_opacityNumberNothe opacity of the image , should be in decimal format. Range is from 0.0 to 1.0 and it defaults to 1.0
background_opacityNumberNothe opacity of the background image , should be in decimal format. Range is from 0.0 to 1.0 and it defaults to 1.0
image_angleNumberNothe angle at which the front image should rotate, should be in numeric format value must be from 0 to 360 and it defaults to 0
image_sizeStringNothe dimensions of the front image file, should be in WidthxHeight format and it defaults to original_size
background_sizeStringNothe dimensions of the background image file, should be in WidthxHeight format and it defaults to original_size
Sample Response
The method returns the image with changed background in the output file mentioned in the URI.

HTTP Response Codes

The method may return one of the following HTTP status codes:
Status CodeDescription
200The request was successful.
401Required authentication information is either missing or not valid for the resource.
400Invalid input - the image files are corrupt.
500If any unexpected error occurs while processing the request.

Authentication

All API requests to ApyHub services need to be authenticated. Currently we support tokens or basic authentication mechanisms. You can generate and view your existing credentials from your workspace settings (on the left side of the navbar) and go to “API Keys".
Points to note:
  • Credential secrets are generated on the fly and are not stored in plain text, so on generating a credential please save the secrets somewhere safe.
  • Use the apy-token as the header parameter to pass the token.
  • Use the Authorization header to send the basic authentication credentials.

Error codes

1
{
2
"error": {
3
"code": 105,
4
"message": "Invalid URL"
5
}
6
}
To search for a specific error code, enter the code in the search box below. Alternatively, you can click on the button to view a complete list of all error codes.