{"id":13589,"date":"2025-11-17T14:38:01","date_gmt":"2025-11-17T12:38:01","guid":{"rendered":"https:\/\/shortpixel.com/blog\/?p=13589"},"modified":"2025-12-13T23:24:35","modified_gmt":"2025-12-13T21:24:35","slug":"5-best-background-removal-apis-with-php-examples","status":"publish","type":"post","link":"https:\/\/shortpixel.com\/blog\/5-best-background-removal-apis-with-php-examples\/","title":{"rendered":"5 Best Background Removal APIs (with PHP Examples)"},"content":{"rendered":"\n<p>Background removal has become a core part of modern image workflows. <\/p>\n\n\n\n<p>From eCommerce product photos to automated media editing, developers now rely on APIs that can isolate subjects using AI while keeping integrations simple. <\/p>\n\n\n\n<p>Below is a curated list of popular services and what they bring to the table.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ShortPixel API<\/h2>\n\n\n\n<p><a href=\"https:\/\/shortpixel.com\/api-docs\" data-type=\"link\" data-id=\"https:\/\/shortpixel.com\/api-docs\">ShortPixel<\/a> offers <a href=\"https:\/\/shortpixel.com\/blog\/our-background-removal-got-a-major-upgrade\/\" data-type=\"link\" data-id=\"https:\/\/shortpixel.com\/blog\/our-background-removal-got-a-major-upgrade\/\">background removal<\/a> as part of its Reducer API, which handles optimization, resizing, conversion, and background removal. You can replace the background with transparency, a solid color, or even a custom image URL.<\/p>\n\n\n\n<p><strong>Key features<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Option to return transparent, solid color, or custom image backgrounds<\/li>\n\n\n\n<li>Works alongside compression and WebP\/AVIF generation<\/li>\n\n\n\n<li>Supports large batch requests through URL lists<\/li>\n\n\n\n<li>Simple JSON-based API and PHP-friendly tooling<\/li>\n<\/ul>\n\n\n\n<p><strong>PHP example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n$URL = \"https:\/\/api.shortpixel.com\/v2\/reducer.php\";\n$APIKey = \"&lt;&lt;YOUR API KEY HERE&gt;&gt;\";\n\n$Data = json_encode(array(\n    \"plugin_version\" =&gt; \"XY123\",\n    \"key\" =&gt; $APIKey,\n    \"lossy\" =&gt; 1,\n    \"bg_remove\" =&gt; 1,\n    \"urllist\" =&gt; array(\n        \"https:\/\/example.com\/image.jpg\"\n    )\n));\n\n$POSTArray = array(\n    'http' =&gt; array(\n        'method'  =&gt; 'POST',\n        'header'  =&gt; \"Content-Type: application\/json\\r\\nAccept: application\/json\\r\\nContent-Length: \" . strlen($Data),\n        'content' =&gt; $Data\n    )\n);\n\n$Context = stream_context_create($POSTArray);\n$Result  = file_get_contents($URL, false, $Context);\n\necho $Result;\n\n?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">remove.bg<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.remove.bg\/api\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.remove.bg\/api\" rel=\"noreferrer noopener\">remove.bg<\/a> is one of the most widely used APIs for automated background removal. It\u2019s built around a straightforward POST request and supports uploads, URLs, and base64 input. The service handles up to 50-megapixel images and returns cutouts in formats like PNG, JPG, WebP, or ZIP for high-performance workflows.<\/p>\n\n\n\n<p>Key features<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Accepts file uploads, URLs, or base64<\/li>\n\n\n\n<li>Output up to 50 MP, depending on format<\/li>\n\n\n\n<li>Supports PNG, JPG, WebP, and ZIP (fastest option with separate color and alpha channels)<\/li>\n\n\n\n<li>Optional extras like cropping, shadows, region of interest, and background replacement<\/li>\n\n\n\n<li>Clear rate-limit rules and credit headers for tracking usage<\/li>\n<\/ul>\n\n\n\n<p><strong>PHP example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nrequire 'vendor\/autoload.php';\n\n$client = new GuzzleHttp\\Client();\n\n$response = $client-&gt;post('https:\/\/api.remove.bg\/v1.0\/removebg', &#91;\n    'multipart' =&gt; &#91;\n        &#91;\n            'name'     =&gt; 'image_file',\n            'contents' =&gt; fopen('\/path\/to\/image.jpg', 'r')\n        ],\n        &#91;\n            'name'     =&gt; 'size',\n            'contents' =&gt; 'auto'\n        ],\n        &#91;\n            'name'     =&gt; 'format',\n            'contents' =&gt; 'png'\n        ]\n    ],\n    'headers' =&gt; &#91;\n        'X-Api-Key' =&gt; 'YOUR_API_KEY'\n    ]\n]);\n\nfile_put_contents('no-bg.png', $response-&gt;getBody());\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Adobe Photoshop API (Background Removal)<\/h2>\n\n\n\n<p>Adobe&#8217;s cloud-based <a href=\"https:\/\/developer.adobe.com\/photoshop\/api\/remove-background\/\" data-type=\"link\" data-id=\"https:\/\/developer.adobe.com\/photoshop\/api\/remove-background\/\" target=\"_blank\" rel=\"noopener\">Photoshop API<\/a> brings some of the same Sensei-powered features from desktop Photoshop into a REST workflow. One of the most popular endpoints is the background-removal service, which generates high-quality masks for product images, marketing assets, and automated creative pipelines.<\/p>\n\n\n\n<p><strong>Key features<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>High-accuracy cutouts powered by Adobe Sensei<\/li>\n\n\n\n<li>Soft or binary mask output<\/li>\n\n\n\n<li>Works with cloud storage locations you define<\/li>\n\n\n\n<li>Fits into automated marketing, e-commerce, and batch-processing flows<\/li>\n<\/ul>\n\n\n\n<p>Adobe doesn\u2019t ship a PHP SDK, but you can call the API normally with any HTTP client (Guzzle works well)<\/p>\n\n\n\n<p><strong>PHP example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nrequire 'vendor\/autoload.php';\n\n$client    = new GuzzleHttp\\Client();\n$apiKey    = 'YOUR_API_KEY';\n$token     = 'YOUR_OAUTH_TOKEN';\n\n\/\/ Adobe requires referencing images through cloud storage.\n\/\/ These values should point to your storage provider and file URLs.\n$inputHref  = 'https:\/\/your-storage\/input.jpg';\n$outputHref = 'https:\/\/your-storage\/output-mask.png';\n\n$payload = &#91;\n    'input' =&gt; &#91;\n        'storage' =&gt; 'external',   \/\/ or adobe depending on setup\n        'href'    =&gt; $inputHref\n    ],\n    'output' =&gt; &#91;\n        'storage' =&gt; 'external',\n        'href'    =&gt; $outputHref,\n        'mask'    =&gt; &#91;\n            'format' =&gt; 'soft'    \/\/ or binary\n        ]\n    ]\n];\n\n$response = $client-&gt;post(\n    'https:\/\/image.adobe.io\/sensei\/mask',\n    &#91;\n        'headers' =&gt; &#91;\n            'x-api-key'      =&gt; $apiKey,\n            'Authorization'  =&gt; 'Bearer ' . $token,\n            'Content-Type'   =&gt; 'application\/json'\n        ],\n        'body' =&gt; json_encode($payload)\n    ]\n);\n\necho $response-&gt;getBody();\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Cloudinary Background Removal Add-on (via Remove.bg or AI models)<\/h2>\n\n\n\n<p>Cloudinary integrates <a href=\"https:\/\/cloudinary.com\/background-remover\" data-type=\"link\" data-id=\"https:\/\/cloudinary.com\/background-remover\" target=\"_blank\" rel=\"noopener\">background removal<\/a> as an add-on service. Developers can run transformations directly through URL parameters or server-side calls.<\/p>\n\n\n\n<p><strong>Key features<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On-the-fly background removal using a single transformation<\/li>\n\n\n\n<li>Optional fine-edge mode for subjects with detailed edges<\/li>\n\n\n\n<li>Combine with any other transformation such as resize, grayscale or underlays<\/li>\n\n\n\n<li>Fast delivery through Cloudinary\u2019s CDN<\/li>\n\n\n\n<li>PHP SDK with simple method chaining for transformations<\/li>\n<\/ul>\n\n\n\n<p><strong>PHP example<\/strong><\/p>\n\n\n\n<p>This example uses Cloudinary\u2019s PHP SDK and applies the background_removal effect when generating a delivery URL. The original stays intact, and the derived result gets cached automatically.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\nuse Cloudinary\\Cloudinary;\nuse Cloudinary\\Transformation\\Effect;\nuse Cloudinary\\Transformation\\Image;\n\n\/\/ Init Cloudinary\n$cloudinary = new Cloudinary(&#91;\n    'cloud' =&gt; &#91;\n        'cloud_name' =&gt; 'your_cloud_name',\n        'api_key'    =&gt; 'your_api_key',\n        'api_secret' =&gt; 'your_api_secret',\n    ]\n]);\n\n\/\/ Create a transformed image URL with background removed\n$url = $cloudinary-&gt;image(\"samples\/dog_couch.jpg\")\n    -&gt;effect(Effect::backgroundRemoval())\n    -&gt;toUrl();\n\necho $url;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Pixelcut API<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.pixelcut.ai\/api\/background-remover\" data-type=\"link\" data-id=\"https:\/\/www.pixelcut.ai\/api\/background-remover\" target=\"_blank\" rel=\"noopener\">Pixelcut<\/a> offers a fast, AI-driven background-removal API built for production workflows. It\u2019s tuned for accurate edge detection and handles high-resolution images without slowing down. Since it powers the Pixelcut app used by millions, the API is stable enough for e-commerce pipelines, creative tools, and automated content generation.<\/p>\n\n\n\n<p><strong>Key features<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sharp edge detection, even around hair, fur and transparent objects<\/li>\n\n\n\n<li>Supports large images up to six thousand pixels<\/li>\n\n\n\n<li>Accepts JPG or PNG and returns clean transparent PNGs or alpha masks<\/li>\n\n\n\n<li>Quick processing with no image retention after completion<\/li>\n\n\n\n<li>Simple JSON request format that\u2019s easy to integrate into any PHP workflow<\/li>\n<\/ul>\n\n\n\n<p><strong>PHP example<\/strong><\/p>\n\n\n\n<p>Pixelcut expects a JSON request containing the image location and desired output format. Here\u2019s a PHP example using standard cURL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n$apiKey   = 'YOUR_API_KEY';\n$imageUrl = 'https:\/\/cdn3.pixelcut.app\/product.jpg';\n\n$payload = json_encode(&#91;\n    'image_url' =&gt; $imageUrl,\n    'format'    =&gt; 'png'   \/\/ transparent PNG output\n]);\n\n$ch = curl_init('https:\/\/api.developer.pixelcut.ai\/v1\/remove-background');\ncurl_setopt_array($ch, &#91;\n    CURLOPT_POST           =&gt; true,\n    CURLOPT_RETURNTRANSFER =&gt; true,\n    CURLOPT_HTTPHEADER     =&gt; &#91;\n        'Content-Type: application\/json',\n        'Accept: application\/json',\n        'X-API-KEY: ' . $apiKey\n    ],\n    CURLOPT_POSTFIELDS     =&gt; $payload\n]);\n\n$response = curl_exec($ch);\ncurl_close($ch);\n\necho $response;\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Background removal has become a core part of modern image workflows. From eCommerce product photos to automated media editing, developers now rely on APIs that can isolate subjects using AI while keeping integrations simple. Below is a curated list of popular services and what they bring to the table. ShortPixel API ShortPixel offers background removal [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":13604,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13589","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-world-of-wordpress"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/posts\/13589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/comments?post=13589"}],"version-history":[{"count":22,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/posts\/13589\/revisions"}],"predecessor-version":[{"id":14046,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/posts\/13589\/revisions\/14046"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/media\/13604"}],"wp:attachment":[{"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/media?parent=13589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/categories?post=13589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shortpixel.com\/blog\/wp-json\/wp\/v2\/tags?post=13589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}