Skip to content

googleapis/google-cloud-php-vision

Google Cloud Vision for PHP

Idiomatic PHP client for Cloud Vision.

Latest Stable Version Packagist

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\Feature\Type;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
use Google\Cloud\Vision\V1\Likelihood;

$client = new ImageAnnotatorClient();

// Annotate an image, detecting faces.
$annotation = $client->annotateImage(
    fopen('/data/photos/family_photo.jpg', 'r'),
    [Type::FACE_DETECTION]
);

// Determine if the detected faces have headwear.
foreach ($annotation->getFaceAnnotations() as $faceAnnotation) {
	$likelihood = Likelihood::name($faceAnnotation->getHeadwearLikelihood());
    echo "Likelihood of headwear: $likelihood" . PHP_EOL;
}

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.

Next Steps

  1. Understand the official documentation.
  2. Take a look at in-depth usage samples.