Remove Image Backgrounds with PixLab API or Web App
Job to be done: Remove image backgrounds at scale using an API or web app
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Small business
Create a professional-looking product catalog for your WhatsApp Business by removing backgrounds from your items (e.g., shoes, food, accessories), making them clear and attractive to customers.
- Entrepreneur
Generate clean, professional product photos for your online store (e.g., fashion, electronics) by removing distracting backgrounds, making your items stand out on Instagram or your website.
- Student
Clean up product photos for your Instagram thrift store or handmade crafts business, making your items look professional and appealing to buyers to fund your studies.
What you’ll get
Clean product photos with the background removed (made transparent), so items look professional for an online store or social media. There are two paths here: a simple web app for removing one image at a time with no code, and an API for developers who want to process many images automatically. (“API” means a service your code calls over the internet.)
Tools you need
- PixLab (freemium): provides both the no-code web app and the developer API for background removal.
- Python (free): only needed for the developer path, to call the API in a script.
Steps
The easy way (no code)
- Use the BG Remove web app: on the PixLab site, open the “BG Remove” web app, upload your image, and download the result. You should get back the same photo with a transparent background, ready to use. For a handful of images, this is all you need.
The developer way (process many automatically)
-
Get your API key: sign up at the PixLab Console and copy your API key (the secret that authorizes your requests). You should see it on your dashboard.
-
Quick test with a URL: if your image is already online, you can remove its background with a single web request. Put your key and image URL into this address and open it:
https://api.pixlab.io/bgremove?img=YOUR_IMAGE_URL&key=YOUR_PIXLAB_API_KEYYou get back a JSON response (a structured data reply) containing the processed image.
-
Process a local image with Python: to handle images on your computer (and many at once), save this as
remove_bg.py, fill in your key and image path, and runpython remove_bg.py:import requests, base64, os API_KEY = 'YOUR_PIXLAB_API_KEY' IMAGE_PATH = 'path/to/your/image.jpg' OUTPUT_PATH = 'output_image.png' url = 'https://api.pixlab.io/bgremove' files = {'img': (os.path.basename(IMAGE_PATH), open(IMAGE_PATH, 'rb'), 'image/jpeg')} data = {'key': API_KEY} response = requests.post(url, files=files, data=data) result = response.json() if result.get('status') == 200 and result.get('imgData'): with open(OUTPUT_PATH, 'wb') as f: f.write(base64.b64decode(result['imgData'])) print(f"Saved background-free image to {OUTPUT_PATH}") else: print("Error:", result.get('error', 'no image data returned'))The API returns the new image as “Base64” text (a way of representing a file as text); the script decodes it and saves a
.png. You should findoutput_image.pngin the folder, background removed.
Original source
Based on “The Background Remove API Devs Actually Ship” by dev_kiran on the DEV Community blog, covering PixLab’s API and companion web app for background removal.
Notes & variations
- Free-tier alternatives: other tools like remove.bg or Adobe Express also remove backgrounds, often with a limited free tier, if you prefer not to use PixLab.
- Common mistake: exposing your API key. Never paste it into public code or a public repository; keep it in an environment variable or config file.
- Tip for better results: for large images or batches, add
blob=trueto the request to get the raw image back instead of Base64 text, which is more efficient, especially if you connect cloud storage in the PixLab Console.