一、功能
(1)实现图片底色替换为红色(白色或蓝色)
二、实现
(1)登录remove.bg,获取API KEY。
(2)使用pip安装 requests和pillow
pip install pillow
pip install requests
(3)remove.bg简单使用
import requests
response = requests.post(
'https://api.remove.bg/v1.0/removebg',
files={'image_file': open('/path/to/file.jpg', 'rb')},
data={'size': 'auto'},
headers={'X-Api-Key': 'INSERT_YOUR_API_KEY_HERE'},
)
if response.status_code == requests.codes.ok:
with open('no-bg.png', 'wb') as out:
out.write(response.content)
else:
print("Error:", response.status_code, response.text)
(4)改造上述方法