Programmatically remove backgrounds from your images using the api
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Adjusted package to accomodate the depreciation of /removebg.json end… Jan 25, 2019
.gitignore Beta launch Jan 1, 2019 Updated readme Jan 29, 2019
phpunit.xml Beta launch Jan 1, 2019

Programmatically remove backgrounds from your images using the api.


Install via composer:

composer require mtownsend/remove-bg

This package is designed to work with any PHP 7.0+ application but has special support for Laravel.

Registering the service provider (Laravel)

For Laravel 5.4 and lower, add the following line to your config/app.php:

 * Package Service Providers...

For Laravel 5.5 and greater, the package will auto register the provider for you.

Using Lumen

To register the service provider, add the following line to app/bootstrap/app.php:


Publishing the config file (Laravel)

php artisan vendor:publish --provider="Mtownsend\RemoveBg\Providers\RemoveBgServiceProvider"

Once your removebg.php has been published your to your config folder, add the api key you obtained from If you are using Laravel and put your api key in the config file, Laravel will automatically set your api key every time you instantiate the class through the helper or facade.

Quick start

Using the class

use Mtownsend\RemoveBg\RemoveBg;

$absoluteUrl = '';
$pathToFile = 'images/avatar.jpg';
$base64EncodedFile = base64_encode(file_get_contents($pathToFile));

$removebg = new RemoveBg($apiKey);

// Directly saving files

// Getting the file's raw contents to save or do something else with
$rawUrl = $removebg->url($absoluteUrl)->get();
$rawFile = $removebg->file($pathToFile)->get();
$rawBase64 = $removebg->base64($base64EncodedFile)->get();

file_put_contents('path/to/your/file4.png', $rawUrl);
// etc...

// Getting the file's base64 encoded contents from the api
$base64Url = $removebg->url($absoluteUrl)->getBase64();
$base64File = $removebg->file($pathToFile)->getBase64();
$base64Base64 = $removebg->base64($base64EncodedFile)->getBase64();

file_put_contents('path/to/your/file5.png', base64_decode($base64Url));
// etc...

// Please note: returns all images in .png format, so you should be saving all files received from the api as .png.

Using the global helper (Laravel)

If you are using Laravel, this package provides a convenient helper function which is globally accessible.


Using the facade (Laravel)

If you are using Laravel, this package provides a facade. To register the facade add the following line to your config/app.php under the aliases key.

'RemoveBg' => Mtownsend\RemoveBg\Facades\RemoveBg::class,
use RemoveBg;




Tests coming soon...

You can run the tests with:



The MIT License (MIT). Please see License File for more information.