php人物图像动漫化

妖狐艹你老母 2023-02-27 05:47 36阅读 0赞
  • 在抖音里面最近人物动漫化的特效比较火,发现百度的图片开发接口上更新了人物动漫这里我们就来使用一下看看效果
  • 需要先去百度的开发平台开通 图像增强与特效 的应用获取相关的key

鉴权认证

向授权服务地址https://aip.baidubce.com/oauth/2.0/token发送请求(推荐使用POST),并在URL中带上以下参数:
grant_type: 必须参数,固定为client_credentials;
client_id: 必须参数,应用的API Key;
client_secret: 必须参数,应用的Secret Key;

  • 返回参数,获取tokenaccess_token

    {

    1. "refresh_token": "25.7b823572a90efb5f667184aa608f6276.315360000.1910241851.282335-21414075",
    2. "expires_in": 2592000,
    3. "session_key": "9mzdCSEI5Jk2pRsDeH7F91AmgoytyYGjKl45/5WiM4Y8xcAy0ljYDzHzSWV+wWqkh4mKSSUrcrY2YbfytfgbVjSSJSGLyQ==",
    4. "access_token": "24.27cdda6153d4a26d17b9b06776d7fcc6.2592000.1597473851.282335-21414075",
    5. "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_虚拟人物助理",
    6. "session_secret": "6840bd72fe477aab81245736d6a3006b"

    }

人物动漫化

  • 访问接口

    $token = ‘24.27cdda6153d4a26d17b9b06776d7fcc6.2592000.1597473851.282335-21414075’;

    1. $url = 'https://aip.baidubce.com/rest/2.0/image-process/v1/selfie_anime?access_token=' . $token;
    2. $img = file_get_contents(public_path().'/ty.jpg');
    3. $img= base64_encode($img);
    4. $bodys = [
    5. 'image' =>$img
    6. ];
    7. $res = $this->request_post($url,$bodys);

    // dd(json_decode($res,true));

    1. file_put_contents(public_path().'/h1.jpg',base64_decode(json_decode($res,true)['image']));//保存图片
  • 请求函数

    function request_post($url = ‘’, $param = ‘’)

    1. {
    2. if (empty($url) || empty($param)) {
    3. return false;
    4. }
    5. $postUrl = $url;
    6. $curlPost = $param;
    7. // 初始化curl
    8. $curl = curl_init();
    9. curl_setopt($curl, CURLOPT_URL, $postUrl);
    10. curl_setopt($curl, CURLOPT_HEADER, 0);
    11. // 要求结果为字符串且输出到屏幕上
    12. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    13. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    14. // post提交方式
    15. curl_setopt($curl, CURLOPT_POST, 1);
    16. curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
    17. // 运行curl
    18. $data = curl_exec($curl);
    19. curl_close($curl);
    20. return $data;
    21. }

效果

  • 个人觉得这个效果看起来像石矶娘娘,不是非常好
    在这里插入图片描述在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,36人围观)

还没有评论,来说两句吧...

相关阅读