php人物图像动漫化
- 在抖音里面最近人物动漫化的特效比较火,发现百度的图片开发接口上更新了人物动漫这里我们就来使用一下看看效果
- 需要先去百度的开发平台开通 图像增强与特效 的应用获取相关的
key
鉴权认证
向授权服务地址https://aip.baidubce.com/oauth/2.0/token发送请求(推荐使用POST),并在URL中带上以下参数:
grant_type: 必须参数,固定为client_credentials;
client_id: 必须参数,应用的API Key;
client_secret: 必须参数,应用的Secret Key;
返回参数,获取
token
即access_token
{
"refresh_token": "25.7b823572a90efb5f667184aa608f6276.315360000.1910241851.282335-21414075",
"expires_in": 2592000,
"session_key": "9mzdCSEI5Jk2pRsDeH7F91AmgoytyYGjKl45/5WiM4Y8xcAy0ljYDzHzSWV+wWqkh4mKSSUrcrY2YbfytfgbVjSSJSGLyQ==",
"access_token": "24.27cdda6153d4a26d17b9b06776d7fcc6.2592000.1597473851.282335-21414075",
"scope": "public brain_all_scope brain_colourize brain_stretch_restore brain_dehaze brain_contrast_enhance brain_image_quality_enhance brain_style_trans brain_image_definition_enhance brain_selfie_anime wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理",
"session_secret": "6840bd72fe477aab81245736d6a3006b"
}
人物动漫化
访问接口
$token = ‘24.27cdda6153d4a26d17b9b06776d7fcc6.2592000.1597473851.282335-21414075’;
$url = 'https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime?access_token=' . $token;
$img = file_get_contents(public_path().'/ty.jpg');
$img= base64_encode($img);
$bodys = [
'image' =>$img
];
$res = $this->request_post($url,$bodys);
// dd(json_decode($res,true));
file_put_contents(public_path().'/h1.jpg',base64_decode(json_decode($res,true)['image']));//保存图片
请求函数
function request_post($url = ‘’, $param = ‘’)
{
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$curlPost = $param;
// 初始化curl
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $postUrl);
curl_setopt($curl, CURLOPT_HEADER, 0);
// 要求结果为字符串且输出到屏幕上
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
// post提交方式
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
// 运行curl
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
效果
- 个人觉得这个效果看起来像石矶娘娘,不是非常好
还没有评论,来说两句吧...