PHP code example of justmd5 / tencent-ai

1. Go to this page and download the library: Download justmd5/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/ */

    

justmd5 / tencent-ai example snippets



$config  = [
    'appKey'    => '1106944xxx',
    'appSecret' => 'dsgnbnWnX8Yxxxxxx',
    'debug'     => true,//true show debug info 
];
$AI      = new \Justmd5\TencentAi\Ai($config);


$params = [
//image 支持两种传递参数方式
//  'image'      => base64_encode(file_get_contents(__DIR__ . '/1571126902_843200.jpg')),//old
    'image'      => __DIR__ . '/1571126902_843200.jpg',//new 
    'session_id' => time(),
];
try {
    var_dump($AI->vision->request('imgtotext', $params));
} catch (\Justmd5\TencentAi\Exception\NotFoundException $e) {
    print_r($e->getMessage());
} catch (\Justmd5\TencentAi\Exception\IllegalParameterException $e) {
    print_r($e->getMessage());
}