API documentation

Get started

  • 1. Sign Up
  • 2. Get your API KEY
  • 3. Review the documentation to work with API

API information

Server
https://api.benzin.io/v1/removeBackground
type
POST

Using algorithms of neural network automatically removes background from any image

  • - File size: up to 12 MB
  • - Image source: File upload (binary or as base64 string) or by URL
  • - Any images are available for processing
  • - Output resolutions: Preview, Full - original image resolution
  • - Requires X-Api-Key header
Request Body
Parameter
size
(string)
Returned image size.
Available values: "full", "preview".
default: preview
channels
(string)
Returned image channels: color image, or mask.
Available values: "rgba", "alpha"
default: rgba
crop
(boolean)
If true, the image will be cropped along the border of the recognized object.
Available values: true, false
default: false
crop_margin
(string)
Defines the offsets from the edges of the cropped image, works only if crop = true, the value could be set in pixels (10px), or in percent (10%), it is possible to set both one value for all edges (for example: 25%), and for paired edges (for example: 10%, 100px), the first value is the left and right edge, the second value is the top and bottom, you can also set all edges separately, e.g. 10%, 25px, 25%, 33%
output_format
(string)
The format that data will be returned.
Available values: "image" - in the form of an image (image/*), "json" - image will be encoded in base64 (application/json)
default: image
image_file
(binary)
Image for processing in binary form
(Use only in multi-part/form-data)
image_file_b64
(string)
Image for processing in base64 format
default: none
image_file_url
(string)
Image for processing by URL
default: none
bg_color
(string)
New background color. Can be specified by color name (white, blue) or by rgb (#fff)
default: none
bg_image_file_b64
(string)
New background image in base64 format
default: none
bg_image_file_url
(string)
New background image by URL
default: none

Responses

Code Description
200
Response if output_format: "image" - binary stream;
Response if output_format: "json" -
{ 
   "image_height":  'val', 
   "image_raw": base64 code, 
   "image_type": "png", 
   "image_width": 'val' 
} 
400
Error: Invalid parameters or input file can`t be processed.
Example: missing image in request
{
  "error": "missing image"
}
Example: header X-Api-Key isn`t set and you want to get size: "full" image
{
 "error": "Токен не задан"
}

Request examples

//Guzzle MULTIPART request - output_format: "image"
$client = new HttpClient(['base_uri' => 'https://api.benzin.io']);
$options = [
    'multipart'=> [
        [
            'name' => 'image_file',
            'contents'=> fopen("your-image.jpg", 'r')
        ],
        [
            'name' => 'size',
            'contents'=> "preview"
        ],
    ],
        'headers' => [
            "X-Api-Key" => "Your Api Key Here"
        ],
    ];
$response = $client->post("/v1/removeBackground", $options);
$fout = fopen("response-image.png", "wb");
fwrite($fout, $response->getBody());
fclose($fout);   
//Guzzle JSON request - output_format: "json"
$client = new HttpClient(['base_uri' => 'https://api.benzin.io']);
$options = [
    'json'=> [
        'image_file_url' => 'https://www.path/to-image.jpg',
        'size' => 'preview',
        'output_format' => 'json'
    ],
    'headers' => [
        "X-Api-Key" => "Your Api Key Here"
    ],
];
$response = $client->post("/v1/removeBackground", $options);
$response->getBody()->getContents(); 
//jQuery AJAX client JSON request - output_format: "json"
jQuery.ajax({
    type: 'POST',
    url: 'https://api.benzin.io/v1/removeBackground',
    dataType: 'json',
    contentType: 'application/json',
    headers:{
        "X-API-Key":"Your Api Key Here"
    },
    data: JSON.stringify({
        "image_file_b64": "b64string",
        "size": "preview",
        "output_format": "json"
    }),
    success: function (data) {
        data = JSON.parse(data);
    }
});