{"id":13616515,"url":"https://github.com/mtownsend5512/remove-bg","last_synced_at":"2025-04-05T01:08:17.443Z","repository":{"id":57021631,"uuid":"163768161","full_name":"mtownsend5512/remove-bg","owner":"mtownsend5512","description":"Programmatically remove backgrounds from your images using the remove.bg api","archived":false,"fork":false,"pushed_at":"2023-06-08T14:36:37.000Z","size":17,"stargazers_count":176,"open_issues_count":0,"forks_count":29,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-29T00:11:17.849Z","etag":null,"topics":["api","background","bg","laravel","php","png","remove","transparent"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mtownsend5512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-01T21:35:17.000Z","updated_at":"2024-12-30T10:35:16.000Z","dependencies_parsed_at":"2024-01-19T11:08:11.949Z","dependency_job_id":"f317b168-86d9-41f2-ba30-a557cd93af5c","html_url":"https://github.com/mtownsend5512/remove-bg","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"c90d2c512b590563ab48c5fdb941a3b849aabda4"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fremove-bg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fremove-bg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fremove-bg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mtownsend5512%2Fremove-bg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mtownsend5512","download_url":"https://codeload.github.com/mtownsend5512/remove-bg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271531,"owners_count":20911587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","background","bg","laravel","php","png","remove","transparent"],"created_at":"2024-08-01T20:01:29.622Z","updated_at":"2025-04-05T01:08:17.425Z","avatar_url":"https://github.com/mtownsend5512.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"Programmatically remove backgrounds from your images using the remove.bg api.\n\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://i.imgur.com/Rrmusuo.png\"\u003e\n\u003c/p\u003e\n\n* [Register an account and obtain your api key](https://www.remove.bg/users/sign_up)\n* [Remove.bg Developer Documentation](https://www.remove.bg/api)\n\n## Installation\n\nInstall via composer:\n\n```\ncomposer require mtownsend/remove-bg\n```\n\n*This package is designed to work with any PHP 7.0+ application but has special support for Laravel.*\n\n### Registering the service provider (Laravel users)\n\nFor Laravel 5.4 and lower, add the following line to your ``config/app.php``:\n\n```php\n/*\n * Package Service Providers...\n */\nMtownsend\\RemoveBg\\Providers\\RemoveBgServiceProvider::class,\n```\n\nFor Laravel 5.5 and greater, the package will auto register the provider for you.\n\n### Using Lumen\n\nTo register the service provider, add the following line to ``app/bootstrap/app.php``:\n\n```php\n$app-\u003eregister(Mtownsend\\RemoveBg\\Providers\\RemoveBgServiceProvider::class);\n```\n\n### Publishing the config file (Laravel users)\n\n````\nphp artisan vendor:publish --provider=\"Mtownsend\\RemoveBg\\Providers\\RemoveBgServiceProvider\"\n````\n\nOnce your ``removebg.php`` has been published your to your config folder, add the api key you obtained from [Remove.bg](https://www.remove.bg/). If you are using Laravel and put your remove.bg api key in the config file, Laravel will automatically set your api key every time you instantiate the class through the helper or facade.\n\n## Quick start\n\n### Using the class\n\n```php\nuse Mtownsend\\RemoveBg\\RemoveBg;\n\n$absoluteUrl = 'https://yoursite.com/images/photo.jpg';\n$pathToFile = 'images/avatar.jpg';\n$base64EncodedFile = base64_encode(file_get_contents($pathToFile));\n\n$removebg = new RemoveBg($apiKey);\n\n// Directly saving files\n$removebg-\u003eurl($absoluteUrl)-\u003esave('path/to/your/file.png');\n$removebg-\u003efile($pathToFile)-\u003esave('path/to/your/file2.png');\n$removebg-\u003ebase64($base64EncodedFile)-\u003esave('path/to/your/file3.png');\n\n// Getting the file's raw contents to save or do something else with\n$rawUrl = $removebg-\u003eurl($absoluteUrl)-\u003eget();\n$rawFile = $removebg-\u003efile($pathToFile)-\u003eget();\n$rawBase64 = $removebg-\u003ebase64($base64EncodedFile)-\u003eget();\n\nfile_put_contents('path/to/your/file4.png', $rawUrl);\n// etc...\n\n// Getting the file's base64 encoded contents from the api\n$base64Url = $removebg-\u003eurl($absoluteUrl)-\u003egetBase64();\n$base64File = $removebg-\u003efile($pathToFile)-\u003egetBase64();\n$base64Base64 = $removebg-\u003ebase64($base64EncodedFile)-\u003egetBase64();\n\nfile_put_contents('path/to/your/file5.png', base64_decode($base64Url));\n// etc...\n\n// Please note: remove.bg returns all images in .png format, so you should be saving all files received from the api as .png.\n```\n\n### Advanced usage\n\nRemove.bg offers several request body parameters for each api call. For an up to date list, you should always check the [remove.bg api documentation](https://www.remove.bg/api).\n\nHere is an example of an api call configured with specific request body parameters.\n\n````php\n$removebg = new RemoveBg($apiKey);\n\n// Directly saving files\n$removebg-\u003eurl($absoluteUrl)\n-\u003ebody([\n    'size' =\u003e '4k', // regular, medium, hd, 4k, auto\n    'bg_color' =\u003e '#CBD5E0',\n    'add_shadow' =\u003e true, // primarily used for automotive photos as of the time this documentation was written\n    'channels' =\u003e 'rgba', // rgba, alpha\n])\n-\u003esave('path/to/your/file.png');\n````\n\nYou may also directly specify request header parameters. As of right now this does not appear to offer much functionality in terms of how the Remove.bg api will consume these headers, but we thought it was important to expose this functionality. Consider the following example:\n\n````php\n$removebg = new RemoveBg($apiKey);\n\n// Directly saving files\n$removebg-\u003eurl($absoluteUrl)\n-\u003eheaders([\n    'X-Foo-Header' =\u003e 'Some Bar Value',\n    'X-Foo-Header-2' =\u003e 'Some Bar Value 2',\n])\n-\u003esave('path/to/your/file.png');\n````\n\n### Account details\n\nThe Remove.bg api offers an endpoint to check your account's credit balance and free api call usage. If your application needs to check your available credits before processing images this package makes it an absolute breeze!\n\nThe following code example is how you can programmatically check your account information. Note, the ``account`` method has one optional argument: `$getResponseAsObject = true`. By default your response will be returned as an object. You can return the response as an associative array by passing `false` to the `account(false)` method.\n\n````php\n$removebg = new RemoveBg($apiKey);\n\n$account = $removebg-\u003eaccount();\n\n// $account will be something like this:\n{\n  \"data\": {\n    \"attributes\": {\n      \"credits\": {\n        \"total\": 200,\n        \"subscription\": 150,\n        \"payg\": 50\n      },\n      \"api\": {\n        \"free_calls\": 50,\n        \"sizes\": \"all\"\n      }\n    }\n  }\n}\n````\n\nTo access your total credits you could do so like this: `$account-\u003edata-\u003eattributes-\u003ecredits-\u003etotal`.\n\nA practical example could look something like the following:\n\n````php\n$removebg = new RemoveBg($apiKey);\n\n$account = $removebg-\u003eaccount();\n\nif ($account-\u003edata-\u003eattributes-\u003ecredits-\u003etotal \u003e= 1) {\n\t$removebg-\u003eurl($absoluteUrl)-\u003esave('path/to/your/file.png');\n}\n````\n\n### Using the global helper (Laravel users)\n\nIf you are using Laravel, this package provides a convenient helper function which is globally accessible.\n\n```php\nremovebg()-\u003eurl($absoluteUrl)-\u003esave(public_path('path/to/your/file.png'));\n```\n\n### Using the facade (Laravel users)\n\nIf 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.\n\n````php\n'RemoveBg' =\u003e Mtownsend\\RemoveBg\\Facades\\RemoveBg::class,\n````\n\n```php\nuse RemoveBg;\n\nRemoveBg::file($pathToFile)-\u003esave(public_path('path/to/your/file.png'));\n```\n\n## Credits\n\n- Mark Townsend\n- [All Contributors](../../contributors)\n\n## Testing\n\n*Tests coming soon...*\n\nYou can run the tests with:\n\n```bash\n./vendor/bin/phpunit\n```\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fremove-bg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmtownsend5512%2Fremove-bg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmtownsend5512%2Fremove-bg/lists"}