@@ -33,22 +33,36 @@ on authenticating your client. Once authenticated, you'll be ready to start maki
3333``` php
3434require 'vendor/autoload.php';
3535
36- use Google\Cloud\Vision\V1\Feature\Type;
37- use Google\Cloud\Vision\V1\ImageAnnotatorClient;
36+ use Google\Cloud\Vision\V1\AnnotateImageRequest;
37+ use Google\Cloud\Vision\V1\BatchAnnotateImagesRequest;
38+ use Google\Cloud\Vision\V1\Client\ImageAnnotatorClient;
39+ use Google\Cloud\Vision\V1\Feature;
40+ use Google\Cloud\Vision\V1\Image;
3841use Google\Cloud\Vision\V1\Likelihood;
3942
4043$client = new ImageAnnotatorClient();
4144
45+ // Prepare the request
46+ $content = file_get_contents('/data/photos/family-photo.jpg', 'r');
47+ $image = (new Image())
48+ ->setContent($content);
49+ $feature = (new Feature())
50+ ->setType(Feature\Type::FACE_DETECTION);
51+ $request = (new AnnotateImageRequest())
52+ ->setImage($image)
53+ ->setFeatures([$feature]);
54+ $batchRequest = (new BatchAnnotateImagesRequest())
55+ ->setRequests([$request]);
56+
4257// Annotate an image, detecting faces.
43- $annotation = $client->annotateImage(
44- fopen('/data/photos/family_photo.jpg', 'r'),
45- [Type::FACE_DETECTION]
46- );
58+ $batchResponse = $client->batchAnnotateImages($batchRequest);
4759
4860// Determine if the detected faces have headwear.
49- foreach ($annotation->getFaceAnnotations() as $faceAnnotation) {
50- $likelihood = Likelihood::name($faceAnnotation->getHeadwearLikelihood());
51- echo "Likelihood of headwear: $likelihood" . PHP_EOL;
61+ foreach ($batchResponse->getResponses() as $response) {
62+ foreach ($response->getFaceAnnotations() as $faceAnnotation) {
63+ $likelihood = Likelihood::name($faceAnnotation->getHeadwearLikelihood());
64+ echo "Likelihood of headwear: $likelihood" . PHP_EOL;
65+ }
5266}
5367```
5468
0 commit comments