API v2
(Click here for older API v1 docs)
Scalable and the fastest way to remove backgrounds automatically.
$ curl -H 'Authorization: YOUR_API_KEY'
-F 'image_file=@/your/image/file.jpg'
-f https://api.backgroundcut.co/v2/cut/
-o output.png
Remove background from image file
$ curl -H 'Authorization: YOUR_API_KEY' \
-F 'image_file=@/your/image/file.jpg' \
-F 'quality=medium' \
-f https://api.backgroundcut.co/v2/cut/ \
-o output.png
import requests
response = requests.post(
'https://api.backgroundcut.co/v2/cut/',
files={'image_file': open('/path/to/file.jpg', 'rb')},
data={'quality': 'high'},
headers={'Authorization': 'YOUR_API_KEY'},
)
if response.status_code == requests.codes.ok:
with open('output.png', 'wb') as out:
out.write(response.content)
else:
print("Error:", response.status_code, response.text)
// Requires "guzzle" to be installed (see guzzlephp.org)
// If you have problems with our SSL certificate with error 'Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)'
// follow these steps to use the latest cacert certificate for cURL: https://github.com/guzzle/guzzle/issues/1935#issuecomment-371756738
$client = new GuzzleHttp\Client();
$res = $client->post('https://api.backgroundcut.co/v2/cut/', [
'multipart' => [
[
'name' => 'image_file',
'contents' => fopen('/path/to/file.jpg', 'r')
],
[
'name' => 'quality',
'contents' => 'medium'
]
],
'headers' => [
'Authorization' => 'YOUR_API_KEY'
]
]);
$fp = fopen("output.png", "wb");
fwrite($fp, $res->getBody());
fclose($fp);
const request = require("request");
const fs = require("fs");
const settings = {
url: "https://api.backgroundcut.co/v2/cut/",
apiKey: "YOUR-API-KEY",
sourceImagePath: "/path/to/file.jpg",
outputImagePath: "output.png"
};
request.post(
{
url: settings.url,
formData: { image_file: fs.createReadStream(settings.sourceImagePath), },
headers: { "Authorization": settings.apiKey, },
encoding: null,
},
function(error, response, body) {
if (error) { console.log(error); return; }
if (response.statusCode != 200) { console.log(body.toString('utf8')); return; }
fs.writeFileSync(settings.outputImagePath, body);
}
);
$ curl -H 'Authorization: Token YOUR_API_KEY' \
-F 'file_url=https://www.example.com/example.jpg' \
-f https://backgroundcut.co/api/v1/cut/
import requests
URL = "https://backgroundcut.co/api/v1/cut/"
data={
'file_url': 'https://www.example.com/example.jpg',
}
headers = {'Authorization': 'Token YOUR_API_KEY'}
response = requests.post(URL, data=data, headers=headers)
print(response.json())
// use Guzzle
// https://docs.guzzlephp.org/en/stable/
post("https://slazzer.com/api/v1/remove_image_background", [
'multipart' => [
[
'name' => 'source_image_file',
'contents' => fopen('SOURCE_IMAGE_FILE_PATH', 'r')
]
],
'headers' => [
'API-KEY' => 'YOUR_API_KEY'
]
]);
$res_body = $res->getBody()->getContents();
echo $res_body;
?>
const axios = require('axios');
const fs = require('fs');
const FormData = require('form-data');
const imagePath = 'YOUR_IMAGE_PATH'
const settings = {
"endpointPath": "https://slazzer.com/api/v1/remove_image_background",
"apiKey": "YOUR_API_KEY"
}
function endpointHeader(apiKey, formdata){
return {
headers: {
'Content-Type':'multipart/form-data; boundary=' + formdata.getBoundary(),
'API-KEY': apiKey
}
}
}
const formdata = new FormData;
formdata.append('source_image_file', fs.createReadStream(imagePath));
axios.post(
settings.endpointPath, formdata, endpointHeader(settings.apiKey, formdata)
)
.then(response => console.log(response.data))
.catch(errors => console.log(errors.response.data));
You can request one of three formats via the "return_type" parameter:
Output Type | Resolution | Pros and cons |
---|---|---|
PNG | Up to 12 Megapixels |
|
ZIP | Up to 12 Megapixels |
|
WEBP | Up to 12 Megapixels |
|
JPG | Up to 12 Megapixels |
WebP is a modern image format that provides superior lossless and lossy compression for images. Depending on the level of compression, it can range from 1 to 100. For example, to get lossless output, you can send a "return_type" parameter as WEBP_100, and to set some compression, you can send the "return_type" parameter as WEBP_50.