The Background Remover API is a Node.js application built with Express that processes images to remove backgrounds using the Photoroom API. This API provides an endpoint for clients to submit image URLs, download the image, and return a version with the background removed.
- Node.js installed on your machine
- An API key from PhotoRoom
- A Canva App ID
- Environment variables configured for
PHOTOROOM_API_KEYandCANVA_APP_ID
Accessing the API:
Use the following endpoint to remove the background from an image:
Request Body:
{
"imageUrl": "string"
}imageUrl: The URL of the image from which the background should be removed.
Response:
- Returns the processed image with the background removed.
- The image is returned as a
png.
-
CORS Configuration:
The application restricts origins based on an allowlist that includes the Canva App's domain. The allowlist is configured using the
CANVA_APP_IDenvironment variable. -
Environment Variables:
PHOTOROOM_API_KEY: The API key for authenticating requests to the PhotoRoom API.CANVA_APP_ID: The ID of the Canva App, used to configure CORS.
The application provides error handling for various scenarios:
- Missing image URL in the request body.
- Failed image download.
- Errors from the PhotoRoom API.
- General server errors.
- PhotoRoom API for image background removal.
- Express.js for the server framework.