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.
<?php
$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);
curl_close($ch);
file_put_contents('wdd.png', $server_output);
?>
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.
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.
<?php
$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);
curl_close($ch);
file_put_contents('wdd.png', $server_output);
?>
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.
Recommanded Articles
- Get Facebook long live access token in AWS Lambda function
- 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
Latest Comments
Miranda
13 Dec 2020Daniel
13 Dec 2020Andrew bishop
18 Dec 2020Aqib Aslam
21 Dec 2020Rony
21 Dec 2020Victor
27 Dec 2020Stella
30 Jun 2021Oben Tabendip
08 Aug 2021Lance
12 Oct 2021Admin
04 Jan 2022