1 | <?php |
||
15 | class Client |
||
16 | { |
||
17 | /** |
||
18 | * Visual Features supported by the Computer Vision API. |
||
19 | * |
||
20 | * @see https://westus.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fa |
||
21 | */ |
||
22 | const FEATURE_CATEGORIES = 'Categories'; |
||
23 | const FEATURE_TAGS = 'Tags'; |
||
24 | const FEATURE_DESCRIPTION = 'Description'; |
||
25 | const FEATURE_FACES = 'Faces'; |
||
26 | const FEATURE_IMAGE_TYPE = 'ImageType'; |
||
27 | const FEATURE_COLOR = 'Color'; |
||
28 | const FEATURE_ADULT = 'Adult'; |
||
29 | |||
30 | /** |
||
31 | * @var string Computer Vision API Key |
||
32 | * |
||
33 | * @see https://azure.microsoft.com/en-us/try/cognitive-services/my-apis/ |
||
34 | */ |
||
35 | private $apiKey = ''; |
||
36 | |||
37 | /** |
||
38 | * @var string Computer Vision API Endpoint, the default should work for most users. |
||
39 | */ |
||
40 | private $endpoint = ''; |
||
41 | |||
42 | /** |
||
43 | * @var HttpClient Guzzle HTTP Client. |
||
44 | */ |
||
45 | private $httpClient; |
||
46 | |||
47 | /** |
||
48 | * Constructor. |
||
49 | * |
||
50 | * @param string $apiKey |
||
51 | * @param string $endpoint |
||
52 | * @param HttpClient|null $httpClient |
||
53 | */ |
||
54 | 2 | public function __construct( |
|
64 | |||
65 | /** |
||
66 | * Analyzes an image. |
||
67 | * |
||
68 | * @param string $imageData Binary image data. |
||
69 | * @param string[] $visualFeatures Features which should be analyzed, see FEATURE_* constants. |
||
70 | * |
||
71 | * @return array Result of the Computer Vision API, the JSON is automatically decoded. |
||
72 | * @see https://docs.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts/php |
||
73 | * |
||
74 | * @throws ClientException |
||
75 | */ |
||
76 | 2 | public function analyze($imageData, $visualFeatures = [self::FEATURE_TAGS]) |
|
106 | } |
||
107 |