php优图人脸融合接口
1.下载优图官方SDK
2.将以下代码添加到TencentYoutuyun/Youtu.php中
public static function faceFusion($image_path) { $real_image_path = realpath($image_path); if (!file_exists($real_image_path)) { return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } $expired = time() + self::EXPIRED_SECONDS; $postUrl = Conf::$END_POINT . 'cgi-bin/pitu_open_access_for_youtu.fcg'; $sign = Auth::appSign($expired, Conf::$USER_ID); $image_data = file_get_contents($real_image_path); $post_data = array( 'app_id' => Conf::$APPID, 'rsp_img_type' => 'url', 'img_data' => base64_encode($image_data), 'opdata' => [array( 'cmd' => 'doFaceMerge', 'params' => array( "model_id"=>"cf_yuren_baozha" ) )] ); $req = array( 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( 'Authorization:'.$sign, 'Content-Type:text/json', ), ); $rsp = Http::send($req); $ret = json_decode($rsp, true); if(!$ret){ return self::getStatusText(); } return $ret; }
3.sample.php中的代码
<?php require('./include.php'); use TencentYoutuyun\Youtu; use TencentYoutuyun\Conf; // 设置APP 鉴权信息 请在http://open.youtu.qq.com 创建应用 $appid='你在优图申请的appid'; $secretId='你在优图申请的secretId'; $secretKey='你在优图申请的secretKey'; $userid='你的QQ号'; Conf::setAppInfo($appid, $secretId, $secretKey, $userid,conf::API_YOUTU_END_POINT ); // 人脸融合 调用列子 error_reporting(0); $uploadRet = YouTu::faceFusion('zxc.jpg'); //图片地址 or 图片名称 echo '<pre>'; print_r($uploadRet); ?>