python RemoveBg api换照片底色

测试了好几个代码,发现还是这个AI的最完美,最蛋疼的是 有各种限制。
偶尔用一次还是可以的
https://www.remove.bg/zh/

注册账号,即可使用API

from removebg import RemoveBg

rmbg = RemoveBg("YOUR-API-KEY", "error.log")
rmbg.remove_background_from_img_file("4.jpg", bg_color='red')#bg_color不写则为透明背景
#rmbg.remove_background_from_img_url("http://www.example.com/some_image.jpg")网络图片
  • img_file_path 图像文件的路径
  • size 输出图像的大小(regular=0.25 MP,HD=4MP,4k=最多10
    MP)。默认值为“regular”
  • bg_color 为图片添加纯色背景。可以是十六进制颜色代码(例如:81d4fa,FFF)或颜色名称(例如green)。
    官方代码
# Requires "requests" to be installed (see python-requests.org)
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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值