PHP code example of khs1994 / tencent-ai

1. Go to this page and download the library: Download khs1994/tencent-ai library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

khs1994 / tencent-ai example snippets




encentAI\TencentAI;
use TencentAI\Exception\TencentAIException;

const APP_ID = 1106560031;
const APP_KEY = 'ZbRY9cf72TbDO0xb';

# you can set return format and request timeout

$ai = TencentAI::getInstance(APP_ID, APP_KEY, false, 10);

$image = __DIR__.'/path/name.jpg';

// must try-catch exception

try {
    $result = $ai->face()->detect($image);
} catch (TencentAIException $e) {
    $result = $e->getExceptionAsArray();
}

// default return array

var_dump($result);



use TencentAI;
use TencentAI\Exception\TencentAIException;

$image = __DIR__.'/path/name.jpg';

try {
    // call by facade
    $result = TencentAI::face()->detect($image);

    // call by helper function
    // tencent_ai()->face()->detect($image);
} catch (TencentAIException $e) {
    $result = $e->getExceptionAsArray();
}

// default return array

var_dump($result);

// use DI

class AI
{
    public $tencent_ai;

    public function __construct(\TencentAI\TencentAI $tencent_ai)
    {
        $this->tencent_ai = $tencent_ai;
    }

    public function demo()
    {
        $image = __DIR__.'/path/name.jpg';

        return $this->tencent_ai->face()->detect($image);
    }
}
bash
$ php artisan vendor:publish --tag=config
bash
export TENCENT_AI_APP_ID
export TENCENT_AI_APP_KEY