Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
<?php
$apiKey = "ここにAPIキーをセット";
$imageNm = $argv[1] ;
$json = json_encode(array(
"requests" => array(
array(
"image" => array(
"content" => base64_encode(file_get_contents($imageNm)),
),
"features" => array(
array(
"type" => "TEXT_DETECTION",
"maxResults" => 10,
),
),
),
),
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://vision.googleapis.com/v1/images:annotate?key=" . $apiKey);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
$res = curl_exec($curl);
$data = json_decode($res, true);
curl_close($curl);
print $data["responses"][0]["fullTextAnnotation"]["text"];
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment