Last active
December 2, 2020 02:25
-
-
Save voduytuan/242de30ffc03413c43f728f5cba1a624 to your computer and use it in GitHub Desktop.
Text Detection with Google Cloud Vision by PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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