public __construct ( resource | string | |
||
$image | resource | string | |
An image to configure with the given settings. This parameter will accept a resource, a string of bytes, or an instance of {@see \Google\Cloud\Storage\StorageObject}. |
$features | array | A list of cloud vision [features](https://cloud.google.com/vision/reference/rest/v1/images/annotate#type) to apply to the image. Google Cloud Platform Client Library provides a set of abbreviated names which can be used in the interest of brevity in place of the names offered by the cloud vision service. These names are `faces`, `landmarks`, `logos`, `labels`, `text`, `safeSearch` and `imageProperties`. |
$options | array | { Configuration Options @type array $maxResults A list of features and the maximum number of results to return. Keys should correspond to feature names given in the `$features` array, and values should be of type int. In all cases where `$maxResults` does not contain a value for a feature, all results will be returned. In cases where a `$maxResults` value is specified, the cloud vision service will return results up to the `$maxResults` value, or the full results, whichever is fewer. @type array $imageContext See [ImageContext](https://cloud.google.com/vision/reference/rest/v1/images/annotate#imagecontext) for full usage details. } |
public function __construct($image, array $features, array $options = [])
{
$this->options = $options + ['imageContext' => [], 'maxResults' => []];
$this->features = $this->normalizeFeatures($features);
if ($image instanceof StorageObject) {
$identity = $image->identity();
$uri = sprintf('gs://%s/%s', $identity['bucket'], $identity['object']);
$this->type = self::TYPE_STORAGE;
$this->image = $uri;
} elseif (is_string($image)) {
$this->type = self::TYPE_STRING;
$this->image = $image;
} elseif (is_resource($image)) {
$this->type = self::TYPE_BYTES;
$this->image = Psr7\stream_for($image);
} else {
throw new InvalidArgumentException('Given image is not valid. ' . 'Image must be a string of bytes, a google storage object, or a resource.');
}
}