1,利用第三方API
api地址: https://www.remove.bg/api#sample-code
$client = new GuzzleHttp\Client(); $res = $client->post('https://api.remove.bg/v1.0/removebg', [ 'multipart' => [ [ 'name' => 'image_file', 'contents' => fopen('/path/to/file.jpg', 'r') ], [ 'name' => 'size', 'contents' => 'auto' ] ], 'headers' => [ 'X-Api-Key' => 'INSERT_YOUR_API_KEY_HERE' ] ]); $fp = fopen("no-bg.png", "wb"); fwrite($fp, $res->getBody()); fclose($fp);
这个方案是最简单的,但是比较贵,同时适合小范围使用。
2,利用开源的自建产品
地址: https://github.com/danielgatis/rembg
Rembg is a tool to remove images background
3,生成海报
第三方api地址: https://mokker.ai/zh/
适合小范围使用,直接调用api生成不错的商品海报