wikisource / google-cloud-vision-php
A PHP interface to Google's Cloud Vision API.
Installs: 1 515
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 8
Forks: 22
Open Issues: 1
Requires
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- ext-gd: *
- phpunit/phpunit: ~5.5
- squizlabs/php_codesniffer: ~2.0
README
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.
Installation
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
.
Usage
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();
Kudos
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