diff --git a/vision/src/detect_image_property.php b/vision/src/detect_image_property.php index faf2e9714f..ffde81fcac 100644 --- a/vision/src/detect_image_property.php +++ b/vision/src/detect_image_property.php @@ -18,29 +18,29 @@ // [START vision_image_property_detection] namespace Google\Cloud\Samples\Vision; -use Google\Cloud\Vision\V1\ImageAnnotatorClient; +use Google\Cloud\Vision\VisionClient; // $path = 'path/to/your/image.jpg' function detect_image_property($path) { - $imageAnnotator = new ImageAnnotatorClient(); + $vision = new VisionClient(); # annotate the image - $image = file_get_contents($path); - $response = $imageAnnotator->imagePropertiesDetection($image); - $props = $response->getImagePropertiesAnnotation(); + $imagePhotoResource = file_get_contents($path); + $image = $vision->image($imagePhotoResource, ['IMAGE_PROPERTIES']); + $annotations = $vision->annotate($image); + $props = $annotations->imageProperties(); print("Properties:" . PHP_EOL); - foreach ($props->getDominantColors()->getColors() as $colorInfo) { - printf("Fraction: %s" . PHP_EOL, $colorInfo->getPixelFraction()); - $color = $colorInfo->getColor(); - printf("Red: %s" . PHP_EOL, $color->getRed()); - printf("Green: %s" . PHP_EOL, $color->getGreen()); - printf("Blue: %s" . PHP_EOL, $color->getBlue()); + foreach ((array) $props->colors() as $colorInfo) { + printf("Fraction: %s" . PHP_EOL, $colorInfo['pixelFraction']); + $color = $colorInfo['color']; + printf("Red: %s" . PHP_EOL, $color['red']); + printf("Green: %s" . PHP_EOL, $color['green']); + printf("Blue: %s" . PHP_EOL, $color['blue']); print(PHP_EOL); } - $imageAnnotator->close(); } // [END vision_image_property_detection] diff --git a/vision/src/detect_image_property_gcs.php b/vision/src/detect_image_property_gcs.php index 201a070303..8ff1d87ecc 100644 --- a/vision/src/detect_image_property_gcs.php +++ b/vision/src/detect_image_property_gcs.php @@ -18,33 +18,27 @@ // [START vision_image_property_detection_gcs] namespace Google\Cloud\Samples\Vision; -use Google\Cloud\Vision\V1\ImageAnnotatorClient; +use Google\Cloud\Vision\VisionClient; // $path = 'gs://path/to/your/image.jpg' function detect_image_property_gcs($path) { - $imageAnnotator = new ImageAnnotatorClient(); + $vision = new VisionClient(); # annotate the image - $response = $imageAnnotator->imagePropertiesDetection($path); - $props = $response->getImagePropertiesAnnotation(); - - - if ($props) { - print("Properties:" . PHP_EOL); - foreach ($props->getDominantColors()->getColors() as $colorInfo) { - printf("Fraction: %s" . PHP_EOL, $colorInfo->getPixelFraction()); - $color = $colorInfo->getColor(); - printf("Red: %s" . PHP_EOL, $color->getRed()); - printf("Green: %s" . PHP_EOL, $color->getGreen()); - printf("Blue: %s" . PHP_EOL, $color->getBlue()); - print(PHP_EOL); - } - } else { - print('No Results.' . PHP_EOL); + $image = $vision->image($path, ['IMAGE_PROPERTIES']); + $annotations = $vision->annotate($image); + $props = $annotations->imageProperties(); + + print("Properties:" . PHP_EOL); + foreach ((array) $props->colors() as $colorInfo) { + printf("Fraction: %s" . PHP_EOL, $colorInfo['pixelFraction']); + $color = $colorInfo['color']; + printf("Red: %s" . PHP_EOL, $color['red']); + printf("Green: %s" . PHP_EOL, $color['green']); + printf("Blue: %s" . PHP_EOL, $color['blue']); + print(PHP_EOL); } - - $imageAnnotator->close(); } // [END vision_image_property_detection_gcs]