How to make image background transparent using PHP
Most of the API's are paid or isn't working perfectly to remove background color from an image. There is an PHP default function imagecolortransparent() is used to define the transparent background of an image while creating image. This is very helpful API for developers & graphic designers.
In this article i will show you how you can remove background color of an image using an API and make the image background transparent without using PHP functions. For this I've used an API remove.bg. To use this API, we need an API KEY, which will we can generate after creating an account.
I will use CURL in PHP using below example in which we will remove background color of an image from an image URL. You need to pass you API Key at place of `API KEY HERE` and enter image URL at place of `Enter Your Image URL here`. Use below code to remove backgorund color from an image.
$url = "https://api.remove.bg/v1.0/removebg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'x-api-key:API KEYE HERE',
// move image_url here:
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image_url' => 'Enter Your Image URL here',
$server_output = curl_exec($ch);
In above code i have use file_put_contents function to store image which getting from curl response.
Steps to create an API KEY
- First create an account on remove.bg
- After login go to `My Dashboard`
- There will be a tab `API Key`
- Click on `show` and use that key in your code
Featurs of This API
- Save time and money: You have to hire a freelancer who takes money for work and it will take time to do that work. Manually editing an image takes so much time and effort, It will takes approx 5 seconds to make a transparent background.
- Simple: Just use above code, change image URL and hit enter. No need to install any heavy software in your system, which results computer running slow.
- Free & Automat: No need to do anything, it is automatically and free.
- How to make image background transparent using PHP
- Paypal credit card payment on website in PHP
- Capture page screenshot by URL php script
- How to get all UK addresses by postal code
- API versioning in Laravel App
- Get all the lists from Mailchimp account using CURL
- Create a LEAD in ZOHO CRM using node js
- Create a LEAD in ZOHO CRM using API
- Add new subscriber in a Klaviyo List API
- Add new subscriber in a Mailchimp List API