PHP SDK

Updated at:

Image Search PHP SDK usage and code examples.

Note

For more product details and technical support, click online consultation or contact us through DingTalk group (35035130).

API list

API name

Description

Add

Add images.

SearchImageByPic

Search using an image.

SearchImageByName

Search using a stored image by name.

SearchImageByText

Search using text. (Available only when the service type is multimodal search for products.)

SearchImageByFilter

Searches for images using filter conditions.

Delete

Delete images.

UpdateImage

Modify images.

Detail

Query instance information.

DumpMeta

Export metadata task.

DumpMetaList

Metadata export task list.

BatchTask

Batch tasks.

BatchTaskList

Batch task list.

CompareSimilarByImage

Compare the similarity of two images.

CheckImageExists

Check if an image exists.

Preparations

Before you install and use the Alibaba Cloud SDK, register an Alibaba Cloud account and generate an AccessKey. See Create an AccessKey.

Note

PHP: >=5.5

Composer mirror

https://developer.aliyun.com/composer

Install dependencies

  • Use Composer to install the SDK.

    composer require alibabacloud/imagesearch-20201214
  • Example composer.json file.

    {
       "require": {
           "alibabacloud/imagesearch-20201214": "^4.4.0"    
        }
    }

Dependency examples

declare (strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\SDK\ImageSearch\V20201214\ImageSearch;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\AddImageAdvanceRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\SearchImageByPicAdvanceRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\SearchImageByNameRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\DeleteImageRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\UpdateImageRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\DetailRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\DumpMetaRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\DumpMetaListRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\IncreaseInstanceRequest;
use AlibabaCloud\SDK\ImageSearch\V20201214\Models\IncreaseListRequest;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;

Add API

  • Code example

    function _addImage()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
     
        $client = new ImageSearch($config);
        $request = new AddImageAdvanceRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
        // Required. The product ID. Maximum length: 256 characters.
        // A product can have multiple images.
        $request->productId = "testPhp";
        // Required. The image name. Maximum length: 256 characters.
        // 1. ProductId + PicName uniquely identifies an image.
        // 2. If you add multiple images with the same ProductId + PicName, the last added image takes precedence and overwrites previously added images.
        $request->picName = "testPhp";
        // Optional. The image category.
        // 1. For product search: If you set a category, the system uses the specified category. If you do not set a category, the system predicts the category. You can get the predicted category in the response.
        // 2. For fabric, trademark, and generic search: The system sets the category to 88888888, regardless of whether you set a category.
        $request->categoryId = 3;
        // Optional. User-defined content. Maximum length: 4096 characters.
        // The system returns this field in queries. For example, add text such as image descriptions.
        $request->customContent = "this is a simple test";
        // Optional. An integer attribute. Use it for filtering in queries. The system returns this field in queries.
        // For example, set different IntAttr values for images from different sites or users. Filter by IntAttr to achieve isolation in queries.
        $request->intAttr = 56;
        // Optional. A string attribute. Maximum length: 128 characters. Use it for filtering in queries. The system returns this field in queries.
        $request->strAttr = "test";
        // Optional. Whether to perform subject identification. Default value: true.
        // 1. If true, the system performs subject identification and searches using the identified subject. You can get the subject identification result in the response.
        // 2. If false, the system does not perform subject identification and searches using the entire image.
        // 3. For fabric image search, this parameter is ignored. The system searches using the entire image.
        $request->crop = true;
        // Optional. The subject region of the image. Format: x1,x2,y1,y2, where x1,y1 are the top-left coordinates and x2,y2 are the bottom-right coordinates. Ensure the specified region does not exceed the image boundaries.
        // If you set Region, the system searches using the specified region, regardless of the Crop parameter value.
        // For fabric image search, this parameter is ignored. The system searches using the entire image.
        $request->region = "167,467,221,407";
        // Image content. Maximum image size: 4 MB. Maximum transfer wait time: 5 seconds. Currently supports PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM image formats.
        // For product, trademark, and generic image search, the image width and height must be between 100 and 4096 pixels.
        // For fabric search, the image width and height must be between 448 and 4096 pixels.
        // Images must not contain rotation information.
    
        // To use a URL, uncomment the following lines.
        // composer require alibabacloud/darabonba-stream
        // use AlibabaCloud\Darabonba\Stream\StreamUtil; 
        // $imageStream = StreamUtil::readFromFilePath("<fileUrl>");  
    
        // Add an image using a file.
        $imageStream = new Stream(fopen("<filePath>", 'r+'));
        $request->picContentObject = $imageStream;
        $runtime = new RuntimeOptions();
        $runtime->maxIdleConns = 3;
        $runtime->connectTimeout = 3000;
        $runtime->readTimeout = 3000;
        try {
            $response = $client->addImageAdvance($request, $runtime);
            var_dump($response->toMap());
          } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } 
    }
  • Result example

    {
      ["requestId"]=>
      string(36) "242CB8B7-DD36-42ED-9A76-37915DC7ED81"
      ["success"]=>
      bool(true)
      ["message"]=>
      string(7) "success"
      ["code"]=>
      int(0)
      ["picInfo"]=>
      array(2) {
        ["CategoryId"]=>
        int(0)
        ["Region"]=>
        string(15) "167,477,221,407"
      }
      ["_name":protected]=>
      array(5) {
        ["requestId"]=>
        string(9) "RequestId"
        ["success"]=>
        string(7) "Success"
        ["message"]=>
        string(7) "Message"
        ["code"]=>
        string(4) "Code"
        ["picInfo"]=>
        string(7) "PicInfo"
      }
      ["_required":protected]=>
      array(0) {
      }
    }

SearchImageByPic API

  • Code example

    function _getImageByPic()
    {
        $config = new Config();
        // For information about how to create an AccessKey, see https://help.aliyun.com/document_detail/116401.htm.
        // An AccessKey provides full access to all APIs. For security, we recommend that you use a RAM user for API calls and routine operations.
        // We strongly recommend that you do not hard-code your AccessKey ID and AccessKey secret in your project code. Leaking your AccessKey can compromise the security of all resources in your account.
        // This example shows how to store your AccessKey in environment variables. You can also store it in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace <regionId> with your instance's region ID. For example, if your instance is in the China (Hangzhou) region, set regionId to "cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace [regionId] with the region ID of your instance. For example, if your instance is in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following code provides an example of how to access the service over a VPC.
        // Note: You can access Image Search over a VPC only from an ECS instance or other resources in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance or resources must also be in the China (Shanghai) region to use the VPC endpoint. If the call fails, ensure that your resources and the Image Search instance are in the same region.
        // $config->endpointType = "internal";  // If you access the Image Search service over a VPC, you must set endpointType to "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC endpoint. Replace [regionId] with your instance's region ID. For example, if your instance is in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new SearchImageByPicAdvanceRequest();
        // Required. The name of your Image Search instance. Specify the instance name, not the instance ID. After you purchase an instance, you can find the instance name in the instance information section of the Image Search console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxx";    
        // The image content. The image can be up to 4 MB in size. The transfer timeout is 5 seconds. The following image formats are supported: PNG, JPG, JPEG, BMP, GIF, WEBP, TIFF, and PPM.
        // For product, trademark, and generic image search, the image width and height must be from 100 to 4,096 pixels.
        // For fabric search, the image width and height must be from 448 to 4,096 pixels.
        // The image cannot contain rotation information.
    
        // To use a URL, uncomment the following lines.
        // composer require alibabacloud/darabonba-stream
        // use AlibabaCloud\Darabonba\Stream\StreamUtil; 
        // $imageStream = StreamUtil::readFromFilePath("<fileUrl>");   
    
        // Search for similar images by using an image file.
        $imageStream = new Stream(fopen("<filePath>", 'r+'));
        $request->picContentObject = $imageStream;   
        // Optional. The image category.
        // 1. For product search: If you provide a category, the system uses it. If not, the system predicts the category and returns the prediction in the response.
        // 2. For fabric, trademark, and generic searches, the system always uses category 88888888.
        $request->categoryId = 3;
        // 1. If `true`, the system identifies the subject, searches for it, and returns the identification result in the response.
        // 2. If this parameter is set to `false`, the system searches for the entire image without performing subject identification.
        // 3. For fabric image search, this parameter is ignored and the system searches for the entire image.
        $request->crop = true;
        // Optional. The subject region of the image, in the format `x1,x2,y1,y2`. The coordinates (x1, y1) and (x2, y2) represent the upper-left and lower-right corners of the region. The region must be within the image boundaries.
        // If you specify a region, the system searches for the specified region regardless of the `crop` parameter value.
        // For fabric image search, this parameter is ignored and the system searches for the entire image.
        $request->region = "167,467,221,407";
        // Optional. The filter conditions. The `int_attr` attribute supports the operators `in`, `not in`, `>`, `>=`, `<`, `<=`, and `=`. The `str_attr` attribute supports the operators `in`, `not in`, `=`, and `!=`. You can use `AND` or `OR` to connect multiple conditions.
        // Examples:
        //  1. Filter results by IntAttr: `int_attr>=100`
        //  2. Filter results by StrAttr: `str_attr!="value1"`
        //  3. Filter results by both IntAttr and StrAttr: `int_attr=1000 AND str_attr="value1"`
        $request->filter = "int_attr=56 AND str_attr =\"test\"";
        // Optional. The similarity threshold.
        // The service returns only images with a similarity score greater than or equal to this threshold. The value must be from 0.00 to 1.00, with up to two decimal places. The default value is 0.00.
        $request->scoreThreshold = "0.54";  
        // Optional. If `true`, groups the response data by `ProductId`.
        $request->distinctProductId = false;
        $runtime = new RuntimeOptions();
        $runtime->maxIdleConns = 3;
        $runtime->connectTimeout = 3000;
        $runtime->readTimeout = 3000;
        try {
            $response = $client->searchImageByPicAdvance($request, $runtime);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    {
      ["requestId"]=>
      string(36) "453517A3-7D00-476E-A946-8CC3B9DC6FA1"
      ["success"]=>
      bool(true)
      ["code"]=>
      int(0)
      ["msg"]=>
      string(7) "success"
      ["auctions"]=>
      array(5) {
        [0]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(7) "vae.jpg"
          ["ProductId"]=>
          string(4) "1000"
          ["SortExprValues"]=>
          string(22) "7.33136443711219e+24;0"
          ["Score"]=>
          float(1)
        }
        [1]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(4) "test"
          ["ProductId"]=>
          string(4) "test"
          ["SortExprValues"]=>
          string(22) "7.33136443711219e+24;0"
          ["Score"]=>
          float(1)
        }
      ........
        [4]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(4) "test"
          ["ProductId"]=>
          string(4) "1000"
          ["SortExprValues"]=>
          string(22) "7.33136443711219e+24;0"
          ["Score"]=>
          float(1)
        }
      }
      ["head"]=>
      array(3) {
        ["DocsFound"]=>
        int(5)
        ["DocsReturn"]=>
        int(5)
        ["SearchTime"]=>
        int(171)
      }
      ["picInfo"]=>
      array(3) {
        ["CategoryId"]=>
        int(0)
        ["MultiRegion"]=>
          array(1) {
            [0]=>
            array(1) {
              ["Region"]=>
              string(15) "134,705,187,785"
            }
         }
        ["AllCategories"]=>
        array(14) {
          [0]=>
          array(2) {
            ["Id"]=>
            int(0)
            ["Name"]=>
            string(4) "Tops"
          }
      ........
          [13]=>
          array(2) {
            ["Id"]=>
            int(88888888)
            ["Name"]=>
            string(5) "Other"
          }
        }
        ["Region"]=>
        string(15) "167,477,221,407"
      }
      ["_name":protected]=>
      array(7) {
        ["requestId"]=>
        string(9) "RequestId"
        ["success"]=>
        string(7) "Success"
        ["code"]=>
        string(4) "Code"
        ["msg"]=>
        string(3) "Msg"
        ["auctions"]=>
        string(8) "Auctions"
        ["head"]=>
        string(4) "Head"
        ["picInfo"]=>
        string(7) "PicInfo"
      }
      ["_required":protected]=>
      array(0) {
      }
    }

SearchImageByName API

  • Code example

    function _getImageByName()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new SearchImageByNameRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxxx";
        // Required. The product ID. Maximum length: 256 characters.
        // A product can have multiple images.
        $request->productId = "testPhp";
        // Required. The image name. Maximum length: 256 characters.
        // 1. ProductId + PicName uniquely identifies an image.
        // 2. If you add multiple images with the same ProductId + PicName, the last added image takes precedence and overwrites previously added images.
        $request->picName = "testPhp";    
        // Optional. The image category.
        // 1. For product search: If you set a category, the system uses the specified category. If you do not set a category, the system predicts the category. You can get the predicted category in the response.
        // 2. For fabric, trademark, and generic search: The system sets the category to 88888888, regardless of whether you set a category.
        $request->categoryId = 3;
        // 1. If true, the system performs subject identification and searches using the identified subject. You can get the subject identification result in the response.
        // 2. If false, the system does not perform subject identification and searches using the entire image.
        // 3. For fabric image search, this parameter is ignored. The system searches using the entire image.
        $request->crop = true;
        // Optional. The subject region of the image. Format: x1,x2,y1,y2, where x1,y1 are the top-left coordinates and x2,y2 are the bottom-right coordinates. Ensure the specified region does not exceed the image boundaries.
        // If you set Region, the system searches using the specified region, regardless of the Crop parameter value.
        // For fabric image search, this parameter is ignored. The system searches using the entire image.
        $request->region = "167,467,221,407";
        // Optional. Filter conditions. int_attr supports the operators in, not in, >, >=, <, <=, and =. str_attr supports the operators in, not in, =, and !=. Connect multiple conditions using AND or OR.
        // Examples:
        //  1. Filter results by IntAttr: int_attr>=100
        //  2. Filter results by StrAttr: str_attr!="value1"
        //  3. Filter results by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
        $request->filter = "int_attr=56 AND str_attr =\"test\"";
        // Optional. Similarity threshold.
        // After you set the similarity score threshold, the system returns only image information with a similarity score greater than or equal to the threshold. The threshold range is 0.00-1.00, with a maximum of two decimal places. Default value: 0.00.
        $request->scoreThreshold= "0.54";  
     
        try {
            $response = $client->SearchImageByName($request);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    ["requestId"]=>
      string(36) "9248A5FC-97AB-4A96-8764-C771CF61D9A1"
      ["success"]=>
      bool(true)
      ["code"]=>
      int(0)
      ["msg"]=>
      string(7) "success"
      ["auctions"]=>
      array(5) {
        [0]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(7) "vae.jpg"
          ["ProductId"]=>
          string(4) "1000"
          ["SortExprValues"]=>
          string(22) "7.33136443711219e+24;0"
          ["Score"]=>
          float(1)
        }
      ........
        [4]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(4) "test"
          ["ProductId"]=>
          string(4) "1000"
          ["SortExprValues"]=>
          string(22) "7.33136443711219e+24;0"
          ["Score"]=>
          float(1)
        }
      }
      ["head"]=>
      array(3) {
        ["DocsFound"]=>
        int(5)
        ["DocsReturn"]=>
        int(5)
        ["SearchTime"]=>
        int(21)
      }
      ["picInfo"]=>
      array(2) {
        ["CategoryId"]=>
        int(0)
        ["MultiRegion"]=>
          array(1) {
            [0]=>
            array(1) {
              ["Region"]=>
              string(15) "134,705,187,785"
            }
        }
        ["AllCategories"]=>
        array(14) {
          [0]=>
          array(2) {
            ["Id"]=>
            int(0)
            ["Name"]=>
            string(4) "Tops"
          }
          ........
          [13]=>
          array(2) {
            ["Id"]=>
            int(88888888)
            ["Name"]=>
            string(5) "Other"
          }
        }
      }
      ["_name":protected]=>
      array(7) {
        ["requestId"]=>
        string(9) "RequestId"
        ["success"]=>
        string(7) "Success"
        ["code"]=>
        string(4) "Code"
        ["msg"]=>
        string(3) "Msg"
        ["auctions"]=>
        string(8) "Auctions"
        ["head"]=>
        string(4) "Head"
        ["picInfo"]=>
        string(7) "PicInfo"
      }
      ["_required":protected]=>
      array(0) {
      }
    }

SearchImageByText API

Important

The SearchImageByText API is available only when the service type is multimodal search for products.

  • Code example

    function _getImageByText()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new SearchImageByTextRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        // Note: This API is available only when the service type is multimodal search for products.
        $request->instanceName = "xxxxxxx";
        // The description text. Supports Chinese and English. Maximum length: 512 characters.
        $request->text = "xxxxxxx";
        // Optional. Filter conditions. int_attr supports the operators in, not in, >, >=, <, <=, and =. str_attr supports the operators in, not in, =, and !=. Connect multiple conditions using AND or OR.
        // Examples:
        //  1. Filter results by IntAttr: int_attr>=100
        //  2. Filter results by StrAttr: str_attr!="value1"
        //  3. Filter results by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
        $request->filter = "int_attr=56 AND str_attr =\"test\"";
        // Optional. Similarity threshold.
        // After you set the similarity score threshold, the system returns only image information with a similarity score greater than or equal to the threshold. The threshold range is 0.00-1.00, with a maximum of two decimal places. Default value: 0.00.
        $request->scoreThreshold= "0.54";  
     
        try {
            $response = $client->searchImageByText($request);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    ["requestId"]=>
      string(36) "9248A5FC-97AB-4A96-8764-C771CF61D9A1"
      ["success"]=>
      bool(true)
      ["code"]=>
      int(0)
      ["msg"]=>
      string(7) "success"
      ["auctions"]=>
      array(5) {
        [0]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(7) "vae.jpg"
          ["ProductId"]=>
          string(4) "1000"
          ["Score"]=>
          float(1)
        }
      ........
        [4]=>
        array(4) {
          ["CategoryId"]=>
          int(0)
          ["PicName"]=>
          string(4) "test"
          ["ProductId"]=>
          string(4) "1000"
          ["Score"]=>
          float(1)
        }
      }
      ["head"]=>
      array(3) {
        ["DocsFound"]=>
        int(5)
        ["DocsReturn"]=>
        int(5)
        ["SearchTime"]=>
        int(21)
      }
      ["picInfo"]=>
      array(2) {
        ["AllCategories"]=>
        array(14) {
          [0]=>
          array(2) {
            ["Id"]=>
            int(0)
            ["Name"]=>
            string(4) "Tops"
          }
          ........
          [13]=>
          array(2) {
            ["Id"]=>
            int(88888888)
            ["Name"]=>
            string(5) "Other"
          }
        }
      }
      ["_name":protected]=>
      array(7) {
        ["requestId"]=>
        string(9) "RequestId"
        ["success"]=>
        string(7) "Success"
        ["code"]=>
        string(4) "Code"
        ["msg"]=>
        string(3) "Msg"
        ["auctions"]=>
        string(8) "Auctions"
        ["head"]=>
        string(4) "Head"
        ["picInfo"]=>
        string(7) "PicInfo"
      }
      ["_required":protected]=>
      array(0) {
      }
    }

SearchImageByFilter API

  • Code example

    function _getImageByFilter()
    {
        $config = new Config();
        // To learn how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm.
        // An AccessKey for an Alibaba Cloud account grants access to all APIs. We recommend that you use a RAM user for API access and routine O&M.
        // We strongly recommend that you do not hard-code your AccessKey ID and AccessKey Secret in your project code. Otherwise, your AccessKeys may be leaked, compromising the security of all resources in your account.
        // This example shows how to store the AccessKey ID and AccessKey Secret in environment variables. You can also store them in a configuration file based on your business needs.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace <regionId> with the ID of the region where your instance is deployed. For example, if your instance is deployed in the China (Hangzhou) region, set regionId to "cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace [regionId] with the ID of the region where your instance is deployed. For example, if your instance is deployed in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
        // The following describes how to access the service over an internal network (VPC).
        // Note: To use an internal network (VPC), your ECS instance and other resources must be in the same region as the Image Search instance. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance must also be in the China (Shanghai) region to use the VPC endpoint. If a connection fails, verify that your resources are in the same region.
        // $config->endpointType = "internal";  // To access the Image Search service over an internal network (VPC), set the endpointType parameter to "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC endpoint. Replace [regionId] with the ID of the region where your instance is deployed. For example, if your instance is deployed in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
        $client = new ImageSearch($config);
        $request = new SearchImageByFilterRequest();
        // Required. The name of the Image Search instance. Note that this is the instance name, not the instance ID. After purchasing an instance, find the instance name in the instance information section of the Image Search console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxx";    
        // Required. The filter expression. The int_attr attribute supports the operators in, not in, >, >=, <, <=, and =. The str_attr attribute supports the operators in, not in, =, and !=. You can use AND or OR to connect multiple conditions.
        // Examples:
        //  1. Filter results by IntAttr: int_attr>=100
        //  2. Filter results by StrAttr: str_attr!="value1"
        //  3. Filter results by IntAttr and StrAttr: int_attr=1000 AND str_attr="value1"
        $request->filter = "int_attr=56 AND str_attr =\"test\"";
        try {
            $response = $client->searchImageByFilter($request);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    {
      ["requestId"]=>
      string(36) "453517A3-7D00-476E-A946-8CC3B9DC6FA1"
      ["success"]=>
      bool(true)
      ["code"]=>
      int(0)
      ["msg"]=>
      string(7) "success"
      ["auctions"]=>
      array(0) {
        
      }
      ["_name":protected]=>
      array(7) {
        ["requestId"]=>
        string(9) "RequestId"
        ["success"]=>
        string(7) "Success"
        ["code"]=>
        string(4) "Code"
        ["msg"]=>
        string(3) "Msg"
        ["auctions"]=>
        string(8) "Auctions"
        ["head"]=>
        string(4) "Head"
        ["picInfo"]=>
        string(7) "PicInfo"
      }
      ["_required":protected]=>
      array(0) {
      }
    }

Delete API

  • Code example

    function _deleteImage()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm.
        // An Alibaba Cloud account's AccessKey provides access to all APIs. We recommend using a RAM user for API calls and routine O&M.
        // To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code. Leaking your AccessKey pair can compromise the security of all resources in your account.
        // This example shows how to store your AccessKey pair in environment variables. You can also store it in a configuration file based on your business needs.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace <regionId> with your instance's region ID. For example, if your instance is deployed in the China (Hangzhou) region, set regionId to "cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace [regionId] with your instance's region ID. For example, if your instance is deployed in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following code is for accessing the service over a VPC.
        // Note: You can access the Image Search service over a VPC only from an ECS instance in the same region. For example, if your Image Search instance is in the China (Shanghai) region, your ECS instance must also be in the China (Shanghai) region to use the VPC endpoint. If a call fails, verify that the ECS instance and the Image Search instance are in the same region.
        // $config->endpointType = "internal";  // To access the Image Search service over a VPC, set the endpointType parameter to "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // Use this endpoint for VPC access. Replace [regionId] with the instance's region ID. For example, if the instance is deployed in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new DeleteImageRequest();
        // Required. The name of the Image Search instance. This is the instance name, not the instance ID. After you purchase an instance, you can find the instance name in the Instance Information section of the Image Search console at https://imagesearch.console.aliyun.com/overview.
        $request->instanceName = "xxxxxx";
        // Required. The product ID. The ID can be up to 256 characters in length.
        // 1. An image is uniquely identified by the combination of its `ProductId` and `PicName`.
        $request->productId = "test";
        // 2. Optional. The image name. Omit this parameter to delete all images under the specified `productId`. If specified, only the image matching both the `productId` and `picName` is deleted.
        $request->picName = "test";
        // Optional. If this parameter is set to true, images are deleted based on the specified `filter`.
        $request->isDeleteByFilter = false;
        $request->filter = "intattr3=xxx";
          
        try {
            $response = $client->deleteImage($request);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    {
      ["requestId"]=>
      string(36) "052ECD87-933D-4E65-94F7-F0C0947E41A1"
      ["success"]=>
      bool(true)
      ["message"]=>
      string(7) "success"
      ["code"]=>
      int(0)
      ["_name":protected]=>
      array(4) {
        ["requestId"]=>
        string(9) "RequestId"
        ["success"]=>
        string(7) "Success"
        ["message"]=>
        string(7) "Message"
        ["code"]=>
        string(4) "Code"
      }
      ["_required":protected]=>
      array(0) {
      }
    }

UpdateImage API

  • Code example

    function _updateImage()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see https://help.aliyun.com/document_detail/116401.htm.
        // An AccessKey pair grants full API access. We recommend using a RAM user for API calls and routine O&M.
        // To avoid security risks, do not hard-code your AccessKey ID and AccessKey Secret in your project code. Leaking your AccessKey pair compromises the security of all resources in your account.
        // This example stores the AccessKey pair in environment variables. You can also use a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace <regionId> with your instance's region ID. For example, for an instance in the China (Hangzhou) region, set regionId to "cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace [regionId] with your instance's region ID. For example, for an instance in the China (Hangzhou) region, set the endpoint to "imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following code shows how to access the service over a VPC.
        // Note: To access the Image Search service over a VPC, your client (such as an ECS instance) must be in the same region as your Image Search instance. For example, if your Image Search instance is in the China (Shanghai) region, your client must also be in the same region to use the VPC endpoint. If the call fails, verify that both resources are in the same region.
        // $config->endpointType = "internal";  // To access the Image Search service over a private network, set the endpointType parameter to "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC endpoint. Replace [regionId] with your instance's region ID. For example, for an instance in the China (Hangzhou) region, set the endpoint to "imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new UpdateImageRequest();
        // Required. The name of the Image Search instance. Note: This is the instance name, not the instance ID. After you purchase an instance, you can find the instance name in the instance information section of the Image Search console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
        // Required. The product ID. You cannot modify the product ID.
        $request->productId = "1";
        // Optional. The image name. If omitted, this operation updates the attributes for all images with the specified productId.
        $request->picName = "1";
        // Optional. The integer attribute. Use this attribute to filter queries. The query results include this attribute.
        $request->intAttr = 10;
        // Optional. The string attribute, up to 128 characters. Use this attribute to filter queries. The query results include this attribute.
        $request->strAttr = "test";
        // Optional. User-defined content, up to 4,096 characters.
        $request->customContent = "This is a test description";
          
        try {
            $response = $client->updateImage($request);
            var_dump($response->body->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    array(3) {
      ["Code"]=>
      int(0)
      ["RequestId"]=>
      string(36) "2CD69717-846D-167A-89AD-647213332248"
      ["Success"]=>
      bool(true)
    }

Detail API

  • Code example

    function _detail()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new DetailRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
          
        try {
            $response = $client->detail($request);
            var_dump($response->body->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    array(3) {
      ["Instance"]=>
      array(8) {
        ["Capacity"]=>
        int(10)
        ["Name"]=>
        string(19) "xxxxxxx"
        ["Qps"]=>
        int(1)
        ["Region"]=>
        string(11) "cn-shanghai"
        ["ServiceType"]=>
        int(0)
        ["TotalCount"]=>
        int(99999)
        ["UtcCreate"]=>
        int(1620382716000)
        ["UtcExpireTime"]=>
        int(1623081600000)
      }
      ["RequestId"]=>
      string(36) "41465B01-11B4-149D-BB6F-BB498B3C39F0"
      ["Success"]=>
      bool(true)
    }

DumpMeta API

  • Code example

    function _dumpMeta()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new DumpMetaRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
          
        try {
            $response = $client->dumpMeta($request);
            var_dump($response->body->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    array(3) {
      ["Data"]=>
      array(2) {
        ["DumpMetaStatus"]=>
        string(10) "PROCESSING"
        ["Id"]=>
        int(572)
      }
      ["RequestId"]=>
      string(36) "A1234E2C-C99E-122C-97D1-F30FE012533B"
      ["Success"]=>
      bool(true)
    }

DumpMetaList API

  • Code example

    function _dumpMetaList()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new DumpMetaListRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
        // Optional. The metadata export task ID.
        $request->id = 567;
        // Optional. The start position of the returned results. Default value: 1.
        $request->pageNumber = 1;
        // Optional. The number of returned results. Default value: 20.
        $request->pageSize = 1;
          
        try {
            $response = $client->dumpMetaList($request);
            var_dump($response->body->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    array(2) {
      ["Data"]=>
      array(4) {
        ["DumpMetaList"]=>
        array(1) {
          [0]=>
          array(7) {
            ["Code"]=>
            string(1) "0"
            ["Id"]=>
            int(567)
            ["MetaUrl"]=>
            string(208) "https://xx/xx"
            ["Msg"]=>
            string(7) "success"
            ["Status"]=>
            string(7) "SUCCESS"
            ["UtcCreate"]=>
            int(1639969113000)
            ["UtcModified"]=>
            int(1639969140000)
          }
        }
        ["PageNumber"]=>
        int(1)
        ["PageSize"]=>
        int(1)
        ["TotalCount"]=>
        int(1)
      }
      ["RequestId"]=>
      string(36) "46044936-BA2E-10E2-9C82-C00FF83862E5"
    }

BatchTask API

  • Code example

    function _batchTask()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new IncreaseInstanceRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
        // Required. The name of the OSS bucket.
        $request->bucketName = "xxxx";
        // Required. The path. It must start with / and not end with /.
        // Prepare the increment.meta file in this path in advance. For more information, see the batch operations document in the user guide.
        $request->path = "/public/xxx";
        // Optional. The callback address for successful requests, http(s)://.
        $request->callbackAddress = "http://xxx/xxx";
          
        try {
            $response = $client->increaseInstance($request);
            var_dump($response->body->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    array(3) {
      ["Data"]=>
      array(2) {
        ["Id"]=>
        int(1475)
        ["IncrementStatus"]=>
        string(10) "PROCESSING"
      }
      ["RequestId"]=>
      string(36) "768C6C02-E3FE-1024-8461-103F7C529EFA"
      ["Success"]=>
      bool(true)
    }

BatchTaskList API

  • Code example

    function _batchTaskList()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new IncreaseListRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
        // Optional. The task ID.
        $request->id = 567;
        // Optional. The name of the OSS bucket to query.
        $request->bucketName = "xxxx";
        // Optional. The OSS path to query.
        $request->path = "/public/xxx";
        // Optional. The start position of the returned results. Default value: 1.
        $request->pageNumber = 1;
        // Optional. The number of returned results. Default value: 20.
        $request->pageSize = 1;
          
        try {
            $response = $client->increaseList($request);
            var_dump($response->body->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    array(2) {
      ["Data"]=>
      array(4) {
        ["Increments"]=>
        array(1) {
          ["Instance"]=>
          array(1) {
            [0]=>
            array(9) {
              ["BucketName"]=>
              string(21) "xxxxx"
              ["Code"]=>
              string(1) "0"
              ["ErrorUrl"]=>
              string(226) "https://xx/xx"
              ["Id"]=>
              int(1464)
              ["Msg"]=>
              string(7) "success"
              ["Path"]=>
              string(23) "/public/xxx"
              ["Status"]=>
              string(6) "NORMAL"
              ["UtcCreate"]=>
              int(1639107872000)
              ["UtcModified"]=>
              int(1639125540000)
            }
          }
        }
        ["PageNumber"]=>
        int(1)
        ["PageSize"]=>
        int(1)
        ["TotalCount"]=>
        int(1)
      }
      ["RequestId"]=>
      string(36) "603C696F-EC04-101F-8767-29A63382237A"
    }

CompareSimilarByImage API

  • Code example

    function _compareSimilarByImage()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://www.alibabacloud.com/help/zh/resource-access-management/latest/accesskey-pairs-create-an-accesskey-pair-for-a-ram-user
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new CompareSimilarByImageAdvanceRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxx";
    
        // To use a URL, uncomment the following lines.
        // composer require alibabacloud/darabonba-stream
        // use AlibabaCloud\Darabonba\Stream\StreamUtil; 
        // $primaryPicContent = StreamUtil::readFromFilePath("<fileUrl>");  
        // $secondaryPicContent = StreamUtil::readFromFilePath("<fileUrl>");  
    
        // Add an image using a file.
        $primaryPicContent = new Stream(fopen("<filePath>", 'r+'));
        $secondaryPicContent = new Stream(fopen("<filePath>", 'r+'));
        $request->primaryPicContentObject = $primaryPicContent;
        $request->secondaryPicContentObject = $secondaryPicContent;
        $runtime = new RuntimeOptions();
        $runtime->maxIdleConns = 3;
        $runtime->connectTimeout = 3000;
        $runtime->readTimeout = 3000;
        try {
            $response = $client->compareSimilarByImageAdvance($request, $runtime);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        }
    }
  • Result example

    {
      ["requestId"]=>
      string(36) "242CB8B7-DD36-42ED-9A76-37915DC7ED81"
      ["success"]=>
      bool(true)
      ["message"]=>
      string(7) "success"
      ["code"]=>
      int(0)
      ["score"]=>
      int(1)
      ["_required":protected]=>
      array(0) {
      }
    }

CheckImageExists API

  • Code example

    function _checkImageExists()
    {
        $config = new Config();
        // For information about how to create an AccessKey pair, see: https://help.aliyun.com/document_detail/116401.htm
        // An Alibaba Cloud account AccessKey has permissions to access all APIs. Use a RAM user for API access and O&M.
        // Do not save the AccessKey ID and AccessKey secret in your project code. This can lead to AccessKey leaks and compromise the security of all resources under your account.
        // This example shows how to save the AccessKey ID and AccessKey secret as environment variables. As needed, save them in a configuration file.
        $config->accessKeyId = getenv("CC_AK_ENV");
        $config->accessKeySecret = getenv("CC_SK_ENV");
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set regionId="cn-hangzhou".
        $config->regionId = "<regionId>";
        // Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch.cn-hangzhou.aliyuncs.com".
        $config->endpoint = "imagesearch.[regionId].aliyuncs.com";
    
        // The following describes VPC access.
        // Note: VPC access is limited to ECS instances or resources in the same region. For example, if you purchased an Image Search instance in China (Shanghai), your ECS instance or resources must also be in China (Shanghai) to access the Image Search service through the VPC address. If the call fails, check if your ECS instance or resources are in the same region as Image Search.
        // $config->endpointType = "internal";  // If you access the Image Search service through a private network, endpointType is required and must be "internal".
        // $config->endpoint = "imagesearch-vpc.[regionId].aliyuncs.com"; // This is the VPC access address. Replace with the region of your purchased instance. For example, if you purchased an instance in Hangzhou, set endpoint="imagesearch-vpc.cn-hangzhou.aliyuncs.com".
    
        $client = new ImageSearch($config);
        $request = new CheckImageExistsRequest();
        // Required. The instance name of Image Search. Note that this is the instance name, not the instance ID. After purchase, view instance information on the console: https://imagesearch.console.aliyun.com/overview
        $request->instanceName = "xxxxxxx";
        // Required. The product ID. Maximum length: 256 characters.
        // A product can have multiple images.
        $request->productId = "testPhp";
        // Required. The image name. Maximum length: 256 characters.
        // 1. ProductId + PicName uniquely identifies an image.
        // 2. If you add multiple images with the same ProductId + PicName, the last added image takes precedence and overwrites previously added images.
        $request->picName = "testPhp";    
     
        try {
            $response = $client->CheckImageExists($request);
            var_dump($response->toMap());
        } catch (TeaUnableRetryError $e) {
            var_dump($e->getLastException(), $e->getLastRequest());
        } catch (Exception $e) {
            var_dump($e->getMessage());
            var_dump($e->getTraceAsString());
        }
    }
  • Result example

    ["requestId"]=>
      string(36) "9248A5FC-97AB-4A96-8764-C771CF61D9A1"
      ["success"]=>
      bool(true)
      ["Exists"]=>
      bool(false)
      ["code"]=>
      int(0)
      ["msg"]=>
      string(7) "success"
    }