Skip to content

Instantly share code, notes, and snippets.

@voduytuan
Last active December 2, 2020 02:25
Show Gist options
  • Save voduytuan/242de30ffc03413c43f728f5cba1a624 to your computer and use it in GitHub Desktop.
Save voduytuan/242de30ffc03413c43f728f5cba1a624 to your computer and use it in GitHub Desktop.
Text Detection with Google Cloud Vision by PHP
# use package "google/cloud-vision": "^1.2.2"
<?php
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
use Google\Cloud\Vision\V1\TextAnnotation;
$imageAnnotatorClient = new ImageAnnotatorClient([
'credentials' => './service-account-key.json'
]);
$imageContent = file_get_contents($imageUrl);
$response = $imageAnnotatorClient->textDetection($imageContent);
$texts = $response->getTextAnnotations();
foreach ($texts as $text) {
$detectedText = $text->getDescription();
$extractedText .= ' ' . $detectedText;
}
echo $extractedText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment