Skip to content

Instantly share code, notes, and snippets.

@ytakky2014
Created November 28, 2016 10:55
Show Gist options
  • Save ytakky2014/447c3e0caf636d5680e18425a3699937 to your computer and use it in GitHub Desktop.
Save ytakky2014/447c3e0caf636d5680e18425a3699937 to your computer and use it in GitHub Desktop.
Use Google Cloud Vision Sample
<?php
use Curl\Curl;
$api_url = env('GOOGLE_CLOUDVISION_API_URL');
$api_key = env('GOOGLE_CLOUDVISION_API_KEY');
$curl = new Curl();
$curl_url = $api_url . $api_key;
$curl->setHeader('Content-Type', 'application/json');
$image_path = 'image_path';
$file = file_get_contents($image_path);
$send_json = json_encode([
"requests" => [
"image" => [
"content" => base64_encode($file)
],
"features" => [
// 物体認識
[
"type" => "LABEL_DETECTION",
"maxResults" => 5
],
],
"imageContext" => [
"languageHints" => "ja"
]
]
]);
$curl->post($curl_url, $send_json);
$response = $curl->response;
var_dump($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment