tp5引入腾讯api接口人像动漫化

1.使用composer 加载腾讯api

1.1.添加中国大陆地区腾讯云镜像高速下载
composer config -g repos.packagist composer https://mirrors.tencent.com/composer/
1.2.在打开的命令窗口执行命令安装 SDK,建议在tp框架目录下
composer require tencentcloud/tencentcloud-sdk-php

2.在tp框架控制层类中引入

use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Ft\V20200304\FtClient;
use TencentCloud\Ft\V20200304\Models\FaceCartoonPicRequest;

3.直接添加方法

public function demo(){
        $SecretId = "你的腾讯云SecretId";
        $SecretKey = "你的腾讯云SecretKey";
        $file_content = file_get_contents("你的图片地址");
        $file_base64 = base64_encode($file_content);
        try {

            $cred = new Credential($SecretId, $SecretKey);
            $httpProfile = new HttpProfile();
            $httpProfile->setEndpoint("ft.tencentcloudapi.com");
              
            $clientProfile = new ClientProfile();
            $clientProfile->setHttpProfile($httpProfile);
            $client = new FtClient($cred, "ap-beijing", $clientProfile);
        
            $req = new FaceCartoonPicRequest();
            
            $params = array(
                "Image" => $file_base64 ,
            );
            $req->fromJsonString(json_encode($params));
        
            $resp = $client->FaceCartoonPic($req);
            $re = $resp->ResultImage;

            echo "";
        }
        catch(TencentCloudSDKException $e) {
            echo $e;
        }
    }

你可能感兴趣的:(tp5,thinkphp5,腾讯云,api,thinkphp)