Change Image Background Programmatically

cURL

curl -H 'X-API-Key: INSERT_YOUR_API_KEY_HERE' \
	-F '[email protected]/path/to/file.jpg' \
	-F 'mode=image' \
	-F 'format=jpg' \
	-F 'background_color=#FFFFFF' \
	-f https://api.photoscissors.com/v1/change-background \
	-o result.jpg

Node.js

// Requires "request" to be installed (see https://www.npmjs.com/package/request)
var request = require('request');
var fs = require('fs');

request.post({
  url: 'https://api.photoscissors.com/v1/change-background',
  formData: {
    image: fs.createReadStream('/path/to/file.jpg'),
    mode: 'image',
	format: 'jpg',
	backround_color: '#FFFFFF'
  },
  headers: {
    'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'
  },
  encoding: null
}, function(error, response, body) {
  if(error) 
  	return console.error('Request failed:', error);
  if(response.statusCode != 200) 
  	return console.error('Error:', response.statusCode, body.toString('utf8'));
  fs.writeFileSync("result.jpg", body);
});

Python

# Requires "requests" to be installed (see python-requests.org)
import requests

response = requests.post(
    'https://api.photoscissors.com/v1/change-background',
    files={'image': open('/path/to/file.jpg', 'rb')},
    data={'mode': 'image', 'format': 'jpg', 'background_color': '#FFFFFF'},
    headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'},
)
if response.status_code == requests.codes.ok:
    with open('result.jpg', 'wb') as out:
        out.write(response.content)
else:
    print("Error:", response.status_code, response.text)

PHP

// Requires "guzzle" to be installed (see guzzlephp.org)

$client = new GuzzleHttp\Client();
$res = $client->post('https://api.photoscissors.com/v1/change-background', [
    'multipart' => [
        [
            'name'     => 'image',
            'contents' => fopen('/path/to/file.jpg', 'r')
        ],
        [
            'name'     => 'mode',
            'contents' => 'image'
        ],
		[
            'name'     => 'format',
            'contents' => 'jpg'
        ],
		[
            'name'     => 'background_color',
            'contents' => '#FFFFFF'
        ]
    ],
    'headers' => [
        'X-Api-Key' => 'INSERT_YOUR_API_KEY_HERE'
    ]
]);

$fp = fopen("result.jpg", "wb");
fwrite($fp, $res->getBody());
fclose($fp);

API Reference

POST: https://api.photoscissors.com/v1/change-background
Removes the background of a JPG/PNG image.
Output resolutions available: up to 4 megapixels

Parameters:

  • image
    Source image file (binary).
  • mode (image or alpha)
    image - returns image without background
    alpha - returs alpha mask.
  • format (jpg or png)
    Result image format
  • background_color
    hex color code