ProductAI® SDKs enable using ProductAI® APIs easily in the programming languege of your choice. You can use our PHP SDKs to send image queries and maintain your datasets.
composer require malong/productai
### Testing
Create a file named ```tests/config.inc.php``` and define constants as follows:
```php
<?php
define('ACCESS_KEY_ID', '');
define('SECRET_KEY', '');
define('IMAGE_SET_ID', '');
define('SERVICE_TYPE_SEARCH', '');
define('SERVICE_ID_SEARCH', '');
define('SERVICE_TYPE_CLASSIFY', '');
define('SERVICE_ID_CLASSIFY', '');
define('SERVICE_TYPE_DETECT', '');
define('SERVICE_ID_DETECT', '');
Run tests:
vendor/bin/phpunit --bootstrap=tests/config.inc.php tests/
use ProductAI;
$product_ai = new ProductAI\API($access_key_id, $secret_key);
$result = $product_ai->searchImage($service_type, $service_id, $url, $loc, $tags, $count, $threshold);
$loc
: Optional, default is the entire image. An area of the image which you want to search. The format is [$x, $y, $w, $h]
.
$tags
: Optional, default is []
. The keywords which you want to search.
$count
: Optional, default is 20. The number of results that between 0 and 100. Public services do NOT support this argument.
$threshold
: Optional, default is 0. A threshold value that between 0 and 1. Set up this argument is NOT recommended.
$result = $product_ai->searchImage($service_type, $service_id, '@'.$filename, $loc, $tags, $count, $threshold);
$result = $product_ai->searchImage($service_type, $service_id, file_get_contents($filename), $loc, $tags, $count, $threshold);
$result = $product_ai->searchImage($service_type, $service_id, '#'.$form_name, $loc, $tags, $count, $threshold);
$result = $product_ai->classifyImage($service_type, $service_id, $image, $loc);
The $image
argument accepts the same type as the image search.
$result = $product_ai->detectImage($service_type, $service_id, $image, $loc);
The $image
argument accepts the same type as the image search.
$result = $product_ai->addImageToSet($set_id, $image_url, 'optional meta', [
'optional tag 1',
'optional tag 2',
]);
$result = $product_ai->addImagesToSet($set_id, [
[
$image_url_1,
'optional meta 1',
[
'optional tag 1',
'optional tag 2',
],
],
[
$image_url_2,
'optional meta 2',
[
'optional tag 3',
'optional tag 4',
],
],
]);
$result = $product_ai->addImagesToSet($set_id, $filename);
$result = $product_ai->removeImagesFromSet($set_id, [
$image_url_1,
$image_url_2,
]);
$result = $product_ai->removeImagesFromSet($set_id, $filename);
## 中文说明
ProductAI® SDK提供了API请求封装与签名验证功能,用户可以轻松使用PHP代码完成API的调用。
### 安装
推荐中国大陆用户使用[国内镜像](https://pkg.phpcomposer.com)。
```shell
composer require malong/productai
创建文件 tests/config.inc.php
并定义如下常量:
<?php
define('ACCESS_KEY_ID', '');
define('SECRET_KEY', '');
define('IMAGE_SET_ID', '');
define('SERVICE_TYPE_SEARCH', '');
define('SERVICE_ID_SEARCH', '');
define('SERVICE_TYPE_CLASSIFY', '');
define('SERVICE_ID_CLASSIFY', '');
define('SERVICE_TYPE_DETECT', '');
define('SERVICE_ID_DETECT', '');
运行测试:
vendor/bin/phpunit --bootstrap=tests/config.inc.php tests/
use ProductAI;
$product_ai = new ProductAI\API($access_key_id, $secret_key);
$result = $product_ai->searchImage($service_type, $service_id, $url, $loc, $tags, $count, $threshold);
$loc
: 可选,默认为整张图片。用于搜索的图片区域,格式为 [$x, $y, $w, $h]
.
$tags
: 可选,默认为 []
。用于筛选搜索结果的标签。
$count
: 可选,默认为 20。 设置返回结果的数量,值为 0 到 100,公共服务不支持此参数。
$threshold
: 可选,默认为 0。设置返回结果的阈值, 值为 0 到 1,不建议设置此参数。
$result = $product_ai->searchImage($service_type, $service_id, '@'.$filename, $loc, $tags, $count, $threshold);
$result = $product_ai->searchImage($service_type, $service_id, file_get_contents($filename), $loc, $tags, $count, $threshold);
$result = $product_ai->searchImage($service_type, $service_id, '#'.$form_name, $loc, $tags, $count, $threshold);
$result = $product_ai->classifyImage($service_type, $service_id, $image, $loc);
$image
参数接受的类型与图像搜索一致。
$result = $product_ai->detectImage($service_type, $service_id, $image, $loc);
$image
参数接受的类型与图像搜索一致。
$result = $product_ai->addImageToSet($set_id, $image_url, 'optional meta', [
'optional tag 1',
'optional tag 2',
]);
$result = $product_ai->addImagesToSet($set_id, [
[
$image_url_1,
'optional meta 1',
[
'optional tag 1',
'optional tag 2',
],
],
[
$image_url_2,
'optional meta 2',
[
'optional tag 3',
'optional tag 4',
],
],
]);
$result = $product_ai->addImagesToSet($set_id, $filename);
$result = $product_ai->removeImagesFromSet($set_id, [
$image_url_1,
$image_url_2,
]);
$result = $product_ai->removeImagesFromSet($set_id, $filename);