当前位置:   article > 正文

让网站用上骚气的人工智能!----全自动抠图_removebg apikey

removebg apikey

每天网上各种人工智能的新闻,但是总觉得是某些大神的玩物。昨日偶然在网上看到一个网站--人工智能抠图工具 Remove.bg。

官网: https://www.remove.bg/

在线人像照片/物品图片背景快速去除工具,你只需要上传图片,它就会利用「人工智能」技术全自动帮你扣掉背景,5 秒钟就能给你一张透明的移除背景后的主体照片。整个过程非常的简单傻瓜,你完完全全不需要花费任何精力去自己抠图。主要是这玩意还全端支持 Win、Mac、Linux 客户端与 PS 插件都有。

上网站注册一个帐户,在个人中心里面会找到api key

登录SSH执行命令就可以愉快的P图了

  1. curl -H 'X-API-Key: YOUR_API_KEY' \
  2. -F 'image_file=@/path/to/file.jpg' \
  3. -f https://api.remove.bg/v1.0/removebg -o no-bg.png

 我的目的显然不是只为了就这样意淫一下,于是打开最近开发的网站项目,里面刚好有客户来图处理,加上自动抠图岂不是瞬间高大上了?废话少说,直接开始。

1、扩展后台接口

2、扩展Helper

  1. public function isRemoveBGAvailable()
  2. {
  3. return Mage::getStoreConfig(self::XML_RB_PATH_APIKEY) && Mage::getStoreConfigFlag(self::XML_RB_PATH_ACTIVE);
  4. }
  5. public function getRemoveBGApiKey() {
  6. return Mage::getStoreConfig(self::XML_RB_PATH_APIKEY);
  7. }

 3、扩展客户图片裁切方法,这里我直接使用了php的exec执行curl方法并返回图象地址到前台

  1. public function cropAction() {
  2. $crop = new CropAvatar(
  3. isset($_POST['avatar_src']) ? $_POST['avatar_src'] : null,
  4. isset($_POST['crop_data']) ? $_POST['crop_data'] : null,
  5. isset($_FILES['avatar_file']) ? $_FILES['avatar_file'] : null
  6. );
  7. $response = array(
  8. 'state' => 200,
  9. 'message' => $crop -> getMsg(),
  10. 'result' => $crop -> getResult(),
  11. 'orginal' => $crop -> getOrginal()
  12. );
  13. if(isset($_POST['removebg']) && Mage::helper('googletag')->isRemoveBGAvailable()){
  14. $key = Mage::helper('googletag')->getRemoveBGApiKey();
  15. $apiKey = 'X-API-Key: '.$key;
  16. $time = date('YmdHis');
  17. $outfileName = $time.'nobg.png';
  18. $path = Mage::getBaseDir('media').'/tmp/tmp/';
  19. $inFile = 'image_file=@'.$crop -> getResult();
  20. $outFile = $path.$outfileName;
  21. $cmd = "curl -H '".$apiKey."' \-F '".$inFile."' \-f https://api.remove.bg/v1.0/removebg -o ".$outFile;
  22. exec($cmd, $output, $return);
  23. $response = array(
  24. 'state' => 200,
  25. 'message' => $crop -> getMsg(),
  26. 'result' => str_replace("/www/wwwroot/site1","",$outFile),
  27. 'orginal' => $crop -> getOrginal()
  28. );
  29. }
  30. echo json_encode($response);
  31. }

点击裁切图象就自动扣好了,直接让美工下岗。

写在最后,这个API商用是需要付费的,因为免费帐户抠图数量是有限制的。 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/954102
推荐阅读
相关标签
  

闽ICP备14008679号