How to use API
Using Python - You can use other programming languages.
1. Remove the image background from the URL
import requests
import base64
url = "https://remove-background-image2.p.rapidapi.com/remove-background"
querystring = {"image_url": "https://raw.githubusercontent.com/ntd119/public_data/main/images/heart.jpg"}
headers = {
"X-RapidAPI-Key": "Your RapidAPI Key",
"X-RapidAPI-Host": "remove-background-image2.p.rapidapi.com"
}
response = requests.request("POST", url, headers=headers, params=querystring)
data = response.json()
status = data.get("status")
if status:
image = data.get("image")
image_bytes = base64.b64decode(image)
with open("image_output.png", "wb") as binary_
binary_file.write(image_bytes)
2. Remove the image background from the local file
import requests
import base64
url = "https://remove-background-image2.p.rapidapi.com/remove-background"
files = {'file': open("C:/Users/admin/Downloads/heart.jpg", 'rb')}
headers = {
"X-RapidAPI-Key": "Your RapidAPI Key",
"X-RapidAPI-Host": "remove-background-image2.p.rapidapi.com"
}
response = requests.request("POST", url, headers=headers, files=files)
data = response.json()
status = data.get("status")
if status:
image = data.get("image")
image_bytes = base64.b64decode(image)
with open("image_output.png", "wb") as binary_
binary_file.write(image_bytes)