Skip to content

Commit 30b7eba

Browse files
authored
chore: upgrade vision samples to new format (GoogleCloudPlatform#1638)
1 parent 11fb77a commit 30b7eba

27 files changed

+230
-498
lines changed

vision/README.md

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,52 +28,15 @@ This simple command-line application demonstrates how to invoke
2828
Run `php composer.phar install` (if composer is installed locally) or `composer install`
2929
(if composer is installed globally).
3030
5. For a basic demonstration of the Cloud Vision API, run `php quickstart.php`.
31-
6. Run `php vision.php` or `php product_search.php`. For `vision.php`, the following commands are available:
32-
```
33-
face Detect faces in an image using Google Cloud Vision API
34-
help Displays help for a command
35-
label Detect labels in an image using Google Cloud Vision API
36-
landmark Detect landmarks in an image using Google Cloud Vision API
37-
list Lists commands
38-
localize-object Detect objects in an image using Google Cloud Vision API
39-
logo Detect logos in an image using Google Cloud Vision API
40-
property Detect image properties in an image using Google Cloud Vision API
41-
safe-search Detect adult content in an image using Google Cloud Vision API
42-
text Detect text in an image using Google Cloud Vision API
43-
crop-hints Detect crop hints in an image using Google Cloud Vision API
44-
document-text Detect document text in an image using Google Cloud Vision API
45-
pdf Detect text in a PDF/TIFF using Google Cloud Vision API
46-
web Detect web entities in an image using Google Cloud Vision API
47-
web-geo Detect web entities in an image with geo metadata using
48-
Google Cloud Vision API
49-
```
50-
For `product_search.php`, the following commands are available:
51-
```
52-
product-create Create a product
53-
product-delete Delete a product
54-
product-get Get information of a product
55-
product-list List information for all products
56-
product-update Update information for a product
57-
product-image-create Create reference image
58-
product-image-delete Delete reference image
59-
product-image-get Get reference image information for a product
60-
product-image-list List all reference image information for a product
61-
product-search-similar Search for similar products to local image
62-
product-search-similar-gcs Search for similar products to GCS image
63-
product-set-create Create a product set
64-
product-set-delete Delete a product set
65-
product-set-get Get information for a product set
66-
product-set-import Import a product set
67-
product-set-list List information for all product sets
68-
product-set-add-product Add product to a product set
69-
product-set-list-products List products in a product set
70-
product-set-remove-product Remove product from a product set
71-
product-purge-orphan Delete all products not in any product sets
72-
product-purge-products-in-product-set Delete all products not in any product set
73-
```
74-
75-
7. Run `php vision.php COMMAND --help` or `php product_search.php COMMAND --help` to print information about the usage of each command.
76-
31+
6. Execute the snippets in the [src/](src/) directory by running
32+
`php src/SNIPPET_NAME.php`. The usage will print for each if no arguments
33+
are provided:
34+
```sh
35+
$ php src/detext_face.php
36+
Usage: php src/detext_face.php <PATH>
37+
38+
$ php src/detect_face.php 'path/to/your/image.jpg'
39+
```
7740
## The client library
7841

7942
This sample uses the [Google Cloud Client Library for PHP][google-cloud-php].

vision/composer.json

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,6 @@
33
"type": "project",
44
"require": {
55
"google/cloud-vision": "^1.0.0",
6-
"google/cloud-storage": "^1.20.1",
7-
"symfony/console": "^5.0"
8-
},
9-
"autoload": {
10-
"psr-4": {
11-
"Google\\Cloud\\Samples\\Vision\\": "src/"
12-
},
13-
"files": [
14-
"src/detect_label.php",
15-
"src/detect_label_gcs.php",
16-
"src/detect_text.php",
17-
"src/detect_text_gcs.php",
18-
"src/detect_face.php",
19-
"src/detect_face_gcs.php",
20-
"src/detect_landmark.php",
21-
"src/detect_landmark_gcs.php",
22-
"src/detect_logo.php",
23-
"src/detect_logo_gcs.php",
24-
"src/detect_safe_search.php",
25-
"src/detect_safe_search_gcs.php",
26-
"src/detect_image_property.php",
27-
"src/detect_image_property_gcs.php",
28-
"src/detect_document_text.php",
29-
"src/detect_document_text_gcs.php",
30-
"src/detect_web.php",
31-
"src/detect_web_gcs.php",
32-
"src/detect_object.php",
33-
"src/detect_object_gcs.php",
34-
"src/detect_web_with_geo_metadata.php",
35-
"src/detect_web_with_geo_metadata_gcs.php",
36-
"src/detect_pdf_gcs.php"
37-
]
6+
"google/cloud-storage": "^1.20.1"
387
}
398
}

vision/src/detect_document_text.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'path/to/your/image.jpg'
24-
25-
function detect_document_text($path)
23+
/**
24+
* @param string $path Path to the image, e.g. "path/to/your/image.jpg"
25+
*/
26+
function detect_document_text(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -67,3 +68,7 @@ function detect_document_text($path)
6768
$imageAnnotator->close();
6869
}
6970
// [END vision_fulltext_detection]
71+
72+
// The following 2 lines are only needed to run the samples
73+
require_once __DIR__ . '/../../testing/sample_helpers.php';
74+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_document_text_gcs.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'gs://path/to/your/image.jpg'
24-
25-
function detect_document_text_gcs($path)
23+
/**
24+
* @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
25+
*/
26+
function detect_document_text_gcs(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -67,3 +68,7 @@ function detect_document_text_gcs($path)
6768
$imageAnnotator->close();
6869
}
6970
// [END vision_fulltext_detection_gcs]
71+
72+
// The following 2 lines are only needed to run the samples
73+
require_once __DIR__ . '/../../testing/sample_helpers.php';
74+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_face.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

2323
// [END vision_face_detection_tutorial_imports]
24-
25-
function detect_face($path, $outFile = null)
24+
/**
25+
* @param string $path Path to the image, e.g. "path/to/your/image.jpg"
26+
* @param string $outFile Saves a copy of the image supplied in $path with a
27+
* rectangle drawn around the detected faces.
28+
*/
29+
function detect_face(string $path, string $outFile = null)
2630
{
2731
// [START vision_face_detection_tutorial_client]
2832
$imageAnnotator = new ImageAnnotatorClient();
@@ -108,3 +112,7 @@ function detect_face($path, $outFile = null)
108112
// [START vision_face_detection]
109113
}
110114
// [END vision_face_detection]
115+
116+
// The following 2 lines are only needed to run the samples
117+
require_once __DIR__ . '/../../testing/sample_helpers.php';
118+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_face_gcs.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'gs://path/to/your/image.jpg'
24-
25-
function detect_face_gcs($path)
23+
/**
24+
* @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
25+
*/
26+
function detect_face_gcs(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -58,3 +59,7 @@ function detect_face_gcs($path)
5859
$imageAnnotator->close();
5960
}
6061
// [END vision_face_detection_gcs]
62+
63+
// The following 2 lines are only needed to run the samples
64+
require_once __DIR__ . '/../../testing/sample_helpers.php';
65+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_image_property.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'path/to/your/image.jpg'
24-
25-
function detect_image_property($path)
23+
/**
24+
* @param string $path Path to the image, e.g. "path/to/your/image.jpg"
25+
*/
26+
function detect_image_property(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -44,3 +45,7 @@ function detect_image_property($path)
4445
$imageAnnotator->close();
4546
}
4647
// [END vision_image_property_detection]
48+
49+
// The following 2 lines are only needed to run the samples
50+
require_once __DIR__ . '/../../testing/sample_helpers.php';
51+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_image_property_gcs.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'gs://path/to/your/image.jpg'
24-
25-
function detect_image_property_gcs($path)
23+
/**
24+
* @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
25+
*/
26+
function detect_image_property_gcs(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -47,3 +48,7 @@ function detect_image_property_gcs($path)
4748
$imageAnnotator->close();
4849
}
4950
// [END vision_image_property_detection_gcs]
51+
52+
// The following 2 lines are only needed to run the samples
53+
require_once __DIR__ . '/../../testing/sample_helpers.php';
54+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_label.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'path/to/your/image.jpg'
24-
25-
function detect_label($path)
23+
/**
24+
* @param string $path Path to the image, e.g. "path/to/your/image.jpg"
25+
*/
26+
function detect_label(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -43,3 +44,7 @@ function detect_label($path)
4344
$imageAnnotator->close();
4445
}
4546
// [END vision_label_detection]
47+
48+
// The following 2 lines are only needed to run the samples
49+
require_once __DIR__ . '/../../testing/sample_helpers.php';
50+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

vision/src/detect_label_gcs.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020

2121
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
2222

23-
// $path = 'gs://path/to/your/image.jpg'
24-
25-
function detect_label_gcs($path)
23+
/**
24+
* @param string $path GCS path to the image, e.g. "gs://path/to/your/image.jpg"
25+
*/
26+
function detect_label_gcs(string $path)
2627
{
2728
$imageAnnotator = new ImageAnnotatorClient();
2829

@@ -42,3 +43,7 @@ function detect_label_gcs($path)
4243
$imageAnnotator->close();
4344
}
4445
// [END vision_label_detection_gcs]
46+
47+
// The following 2 lines are only needed to run the samples
48+
require_once __DIR__ . '/../../testing/sample_helpers.php';
49+
\Google\Cloud\Samples\execute_sample(__FILE__, __NAMESPACE__, $argv);

0 commit comments

Comments
 (0)