This is a simple PHP interface to the Google Cloud Vision API.
Features:
- Supports almost all features of the Cloud Vision API (version 1).
- Loads images from files, URLs, raw data, or Google Cloud Storage.
Requirements:
- PHP ≥ 5.6
- API key (see Google's Getting Started documentation)
To install, first add this to your composer.json
:
"require": {
"wikisource/google-cloud-vision-php": "^1.2"
}
...and run composer update
.
use GoogleCloudVisionPHP\GoogleCloudVision;
$gcv = new GoogleCloudVision();
// Get your API key from the Google Cloud Platform site.
$gcv->setKey("[Key from Google]");
// An image can be set from either a filename or URL (the default), raw data, or a Google Cloud Storage item:
$gcv->setImage("local/filesystem/file.png");
$gcv->setImage("https://example.org/url/to/file.png");
$gcv->setImage(file_get_contents('local/file.png'), GoogleCloudVision::IMAGE_TYPE_RAW);
$gcv->setImage("gs://bucket_name/object_name", GoogleCloudVision::IMAGE_TYPE_GCS);
// Set which features you want to retrieve:
$gcv->addFeatureUnspecified(1);
$gcv->addFeatureFaceDetection(1);
$gcv->addFeatureLandmarkDetection(1);
$gcv->addFeatureLogoDetection(1);
$gcv->addFeatureLabelDetection(1);
$gcv->addFeatureTextDetection(1);
$gcv->addFeatureDocumentTextDetection(1);
$gcv->addFeatureSafeSeachDetection(1);
$gcv->addFeatureImageProperty(1);
// Optional. The API will try to guess the language if you don't set this.
$gcv->setImageContext(['languageHints' => ['th']]);
$response = $gcv->request();
This is a fork of thangman22's original library, and all credit goes to them.
Test images are from:
Munich_subway_station_Hasenbergl_2.JPG
by Martin Falbisoner CC BY-SA 4.0 via Wikimedia Commons