Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions vision/src/detect_image_property.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@
// [START vision_image_property_detection]
namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\VisionClient;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;

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

function detect_image_property($path)
{
$vision = new VisionClient();
$imageAnnotator = new ImageAnnotatorClient();

# annotate the image
$imagePhotoResource = file_get_contents($path);
$image = $vision->image($imagePhotoResource, ['IMAGE_PROPERTIES']);
$annotations = $vision->annotate($image);
$props = $annotations->imageProperties();
$image = file_get_contents($path);
$response = $imageAnnotator->imagePropertiesDetection($image);
$props = $response->getImagePropertiesAnnotation();

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']);
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);
}

$imageAnnotator->close();
}
// [END vision_image_property_detection]
34 changes: 20 additions & 14 deletions vision/src/detect_image_property_gcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,33 @@
// [START vision_image_property_detection_gcs]
namespace Google\Cloud\Samples\Vision;

use Google\Cloud\Vision\VisionClient;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;

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

function detect_image_property_gcs($path)
{
$vision = new VisionClient();
$imageAnnotator = new ImageAnnotatorClient();

# annotate the image
$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);
$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);
}

$imageAnnotator->close();
}
// [END vision_image_property_detection_gcs]