NOTE: This repository is part of Google Cloud PHP. Any
support requests, bug reports, or development contributions should be directed to
that project.
Allows developers to easily integrate vision detection features within applications, including image labeling, face and
landmark detection, optical character recognition (OCR), and tagging of explicit content.
Installation
To begin, install the preferred dependency manager for PHP, Composer.
Now install this component:
$ composer require google/cloud-vision
Authentication
Please see our Authentication guide for more information
on authenticating your client. Once authenticated, you'll be ready to start making requests.
Sample
require 'vendor/autoload.php';
use Google\Cloud\Vision\V1\AnnotateImageRequest;
use Google\Cloud\Vision\V1\BatchAnnotateImagesRequest;
use Google\Cloud\Vision\V1\Client\ImageAnnotatorClient;
use Google\Cloud\Vision\V1\Feature;
use Google\Cloud\Vision\V1\Image;
use Google\Cloud\Vision\V1\Likelihood;
$client = new ImageAnnotatorClient();
// Prepare the request
$content = file_get_contents('/data/photos/family-photo.jpg', 'r');
$image = (new Image())
->setContent($content);
$feature = (new Feature())
->setType(Feature\Type::FACE_DETECTION);
$request = (new AnnotateImageRequest())
->setImage($image)
->setFeatures([$feature]);
$batchRequest = (new BatchAnnotateImagesRequest())
->setRequests([$request]);
// Annotate an image, detecting faces.
$batchResponse = $client->batchAnnotateImages($batchRequest);
// Determine if the detected faces have headwear.
foreach ($batchResponse->getResponses() as $response) {
foreach ($response->getFaceAnnotations() as $faceAnnotation) {
$likelihood = Likelihood::name($faceAnnotation->getHeadwearLikelihood());
echo "Likelihood of headwear: $likelihood" . PHP_EOL;
}
}
Debugging
Please see our Debugging guide
for more information about the debugging tools.
Version
This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in
any minor or patch releases. We will address issues and requests with the highest priority.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [2.0.3 (latest)](/php/docs/reference/cloud-vision/latest)\n- [2.0.2](/php/docs/reference/cloud-vision/2.0.2)\n- [1.10.3](/php/docs/reference/cloud-vision/1.10.3)\n- [1.9.4](/php/docs/reference/cloud-vision/1.9.4)\n- [1.8.0](/php/docs/reference/cloud-vision/1.8.0)\n- [1.7.6](/php/docs/reference/cloud-vision/1.7.6)\n- [1.6.8](/php/docs/reference/cloud-vision/1.6.8) \n\nGoogle Cloud Vision for PHP\n===========================\n\n\u003e Idiomatic PHP client for [Cloud Vision](https://cloud.google.com/vision/).\n\n[](https://packagist.org/packages/google/cloud-vision) [](https://packagist.org/packages/google/cloud-vision)\n\n**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any\nsupport requests, bug reports, or development contributions should be directed to\nthat project.\n\nAllows developers to easily integrate vision detection features within applications, including image labeling, face and\nlandmark detection, optical character recognition (OCR), and tagging of explicit content.\n\n### Installation\n\nTo begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/).\n\nNow install this component: \n\n $ composer require google/cloud-vision\n\n### Authentication\n\nPlease see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information\non authenticating your client. Once authenticated, you'll be ready to start making requests.\n\n### Sample\n\n require 'vendor/autoload.php';\n\n use Google\\Cloud\\Vision\\V1\\AnnotateImageRequest;\n use Google\\Cloud\\Vision\\V1\\BatchAnnotateImagesRequest;\n use Google\\Cloud\\Vision\\V1\\Client\\ImageAnnotatorClient;\n use Google\\Cloud\\Vision\\V1\\Feature;\n use Google\\Cloud\\Vision\\V1\\Image;\n use Google\\Cloud\\Vision\\V1\\Likelihood;\n\n $client = new ImageAnnotatorClient();\n\n // Prepare the request\n $content = file_get_contents('/data/photos/family-photo.jpg', 'r');\n $image = (new Image())\n -\u003esetContent($content);\n $feature = (new Feature())\n -\u003esetType(Feature\\Type::FACE_DETECTION);\n $request = (new AnnotateImageRequest())\n -\u003esetImage($image)\n -\u003esetFeatures([$feature]);\n $batchRequest = (new BatchAnnotateImagesRequest())\n -\u003esetRequests([$request]);\n\n // Annotate an image, detecting faces.\n $batchResponse = $client-\u003ebatchAnnotateImages($batchRequest);\n\n // Determine if the detected faces have headwear.\n foreach ($batchResponse-\u003egetResponses() as $response) {\n foreach ($response-\u003egetFaceAnnotations() as $faceAnnotation) {\n $likelihood = Likelihood::name($faceAnnotation-\u003egetHeadwearLikelihood());\n echo \"Likelihood of headwear: $likelihood\" . PHP_EOL;\n }\n }\n\n### Debugging\n\nPlease see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md)\nfor more information about the debugging tools.\n\n### Version\n\nThis component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in\nany minor or patch releases. We will address issues and requests with the highest priority.\n\n### Next Steps\n\n1. Understand the [official documentation](https://cloud.google.com/vision/docs/).\n2. Take a look at [in-depth usage samples](https://github.com/GoogleCloudPlatform/php-docs-samples/tree/master/vision/)."]]