Skip to content

Commit 01c04b3

Browse files
sirtorrybshaffer
authored andcommitted
Revert "[detect_image_property] Update to new Vision client" (GoogleCloudPlatform#764)
1 parent 30e911a commit 01c04b3

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

vision/src/detect_image_property.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,29 @@
1818
// [START vision_image_property_detection]
1919
namespace Google\Cloud\Samples\Vision;
2020

21-
use Google\Cloud\Vision\VisionClient;
21+
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

2323
// $path = 'path/to/your/image.jpg'
2424

2525
function detect_image_property($path)
2626
{
27-
$vision = new VisionClient();
27+
$imageAnnotator = new ImageAnnotatorClient();
2828

2929
# annotate the image
30-
$imagePhotoResource = file_get_contents($path);
31-
$image = $vision->image($imagePhotoResource, ['IMAGE_PROPERTIES']);
32-
$annotations = $vision->annotate($image);
33-
$props = $annotations->imageProperties();
30+
$image = file_get_contents($path);
31+
$response = $imageAnnotator->imagePropertiesDetection($image);
32+
$props = $response->getImagePropertiesAnnotation();
3433

3534
print("Properties:" . PHP_EOL);
36-
foreach ((array) $props->colors() as $colorInfo) {
37-
printf("Fraction: %s" . PHP_EOL, $colorInfo['pixelFraction']);
38-
$color = $colorInfo['color'];
39-
printf("Red: %s" . PHP_EOL, $color['red']);
40-
printf("Green: %s" . PHP_EOL, $color['green']);
41-
printf("Blue: %s" . PHP_EOL, $color['blue']);
35+
foreach ($props->getDominantColors()->getColors() as $colorInfo) {
36+
printf("Fraction: %s" . PHP_EOL, $colorInfo->getPixelFraction());
37+
$color = $colorInfo->getColor();
38+
printf("Red: %s" . PHP_EOL, $color->getRed());
39+
printf("Green: %s" . PHP_EOL, $color->getGreen());
40+
printf("Blue: %s" . PHP_EOL, $color->getBlue());
4241
print(PHP_EOL);
4342
}
4443

44+
$imageAnnotator->close();
4545
}
4646
// [END vision_image_property_detection]

vision/src/detect_image_property_gcs.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,33 @@
1818
// [START vision_image_property_detection_gcs]
1919
namespace Google\Cloud\Samples\Vision;
2020

21-
use Google\Cloud\Vision\VisionClient;
21+
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

2323
// $path = 'gs://path/to/your/image.jpg'
2424

2525
function detect_image_property_gcs($path)
2626
{
27-
$vision = new VisionClient();
27+
$imageAnnotator = new ImageAnnotatorClient();
2828

2929
# annotate the image
30-
$image = $vision->image($path, ['IMAGE_PROPERTIES']);
31-
$annotations = $vision->annotate($image);
32-
$props = $annotations->imageProperties();
33-
34-
print("Properties:" . PHP_EOL);
35-
foreach ((array) $props->colors() as $colorInfo) {
36-
printf("Fraction: %s" . PHP_EOL, $colorInfo['pixelFraction']);
37-
$color = $colorInfo['color'];
38-
printf("Red: %s" . PHP_EOL, $color['red']);
39-
printf("Green: %s" . PHP_EOL, $color['green']);
40-
printf("Blue: %s" . PHP_EOL, $color['blue']);
41-
print(PHP_EOL);
30+
$response = $imageAnnotator->imagePropertiesDetection($path);
31+
$props = $response->getImagePropertiesAnnotation();
32+
33+
34+
if ($props) {
35+
print("Properties:" . PHP_EOL);
36+
foreach ($props->getDominantColors()->getColors() as $colorInfo) {
37+
printf("Fraction: %s" . PHP_EOL, $colorInfo->getPixelFraction());
38+
$color = $colorInfo->getColor();
39+
printf("Red: %s" . PHP_EOL, $color->getRed());
40+
printf("Green: %s" . PHP_EOL, $color->getGreen());
41+
printf("Blue: %s" . PHP_EOL, $color->getBlue());
42+
print(PHP_EOL);
43+
}
44+
} else {
45+
print('No Results.' . PHP_EOL);
4246
}
47+
48+
$imageAnnotator->close();
4349
}
4450
// [END vision_image_property_detection_gcs]

0 commit comments

Comments
 (0)