Please review Pricing before use, as a separate charge is incurred for each feature performed on an image. When practical, caching of results is certainly recommended. The Cloud Vision API supports a variety of image file formats, including JPEG, PNG8, PNG24, Animated GIF (first frame only), and RAW. Cloud Vision sets upper limits on file size as well as on the total combined size of all images in a request. Reducing your file size can significantly improve throughput; however, be careful not to reduce image quality in the process. See Best Practices - Image Sizing for current file size limits. Example: [snippet=default] use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $vision = $cloud->vision(); $imageResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = $vision->image($imageResource, [ 'FACE_DETECTION' ]); [snippet=direct] Images can be directly instantiated. use Google\Cloud\Vision\Image; $imageResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = new Image($imageResource, [ 'FACE_DETECTION' ]); [snippet=string] Image data can be given as a string use Google\Cloud\Vision\Image; $imageData = file_get_contents(__DIR__ .'/assets/family-photo.jpg'); $image = new Image($imageData, [ 'FACE_DETECTION' ]); [snippet=gcs] Files stored in Google Cloud Storage can be used. use Google\Cloud\Vision\Image; $file = $cloud->storage()->bucket('my-test-bucket')->object('family-photo.jpg'); $image = new Image($file, [ 'FACE_DETECTION' ]); [snippet=max] This example sets a maximum results limit on one feature and provides some image context. use Google\Cloud\Vision\Image; $imageResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = new Image($imageResource, [ 'FACE_DETECTION', 'LOGO_DETECTION' ], [ 'maxResults' => [ 'FACE_DETECTION' => 1 ], 'imageContext' => [ 'latLongRect' => [ 'minLatLng' => [ 'latitude' => '-45.0', 'longitude' => '-45.0' ], 'maxLatLng' => [ 'latitude' => '45.0', 'longitude' => '45.0' ] ] ] ]); [snippet=shortcut] The client library also offers shortcut names which can be used in place of the longer feature names. use Google\Cloud\Vision\Image; $imageResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = new Image($imageResource, [ 'faces', // Corresponds to FACE_DETECTION 'landmarks', // Corresponds to LANDMARK_DETECTION 'logos', // Corresponds to LOGO_DETECTION 'labels', // Corresponds to LABEL_DETECTION 'text', // Corresponds to TEXT_DETECTION 'safeSearch', // Corresponds to SAFE_SEARCH_DETECTION 'imageProperties' // Corresponds to IMAGE_PROPERTIES ]);
See also: https://cloud.google.com/vision/docs/image-best-practices Best Practices
See also: https://cloud.google.com/vision/docs/pricing Pricing
 public function testBytesWithoutEncoding()
 {
     $bytes = 'foo';
     $image = new Image($bytes, ['landmarks']);
     $res = $image->requestObject(false);
     $this->assertEquals($res['image']['content'], $bytes);
     $encodedRes = $image->requestObject();
     $this->assertEquals($encodedRes['image']['content'], base64_encode($bytes));
 }