wikisource/google-cloud-vision-php

此包已被弃用,不再维护。作者建议使用google/cloud-vision包代替。

Google云视觉API的PHP接口。

1.2.0 2017-09-18 06:10 UTC

This package is auto-updated.

Last update: 2021-05-21 03:04:01 UTC


README

这是一个简单的PHP接口,用于Google Cloud Vision API

Build Status Scrutinizer Code Quality

特性

  • 支持Cloud Vision API(版本1)的几乎所有功能。
  • 可以从文件、URL、原始数据或Google Cloud Storage加载图片。

安装

要求

  • PHP ≥ 5.6
  • API密钥(见Google的入门文档)

要安装,首先将其添加到您的composer.json

    "require": {
        "wikisource/google-cloud-vision-php": "^1.2"
    }

...然后运行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();

赞赏

这是thangman22原始库的分支,所有功劳都属于他们。

测试图片来自

  1. Munich_subway_station_Hasenbergl_2.JPG by Martin Falbisoner CC BY-SA 4.0 via Wikimedia Commons