Zerewan / highlight-text-in-image

Find and highlight Text in Images using Google Cloud Vision API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Highlight Text in Image

Lets you check for and highlight strings in images utilizing Googles Cloud Vision API

Installation

$ composer require janrop/highlight-text-in-image

Before using you need to download a Google Authentication Details .json file and reference it in the GOOGLE_APPLICATION_CREDENTIALS environment variable:

putenv('GOOGLE_APPLICATION_CREDENTIALS=./path_to/google_application_credentials.json');

Usage

use Janrop\TextInImageHighlighter;
$image = fopen(__DIR__ . '/Lorem_Ipsum_Helvetica.png', 'r');

$highlighter = new \Janrop\TextInImageHighlighter($image);

# Check if String "Foo" exists in document.
# If it does  highlight it with a green border.
# If not highlight all Blocks containing "Bar" with a red border.
if($highlighter->find('Foo')->countMatches()){
    $highlighter->highlight([0, 255, 0], 3);
}else{
    $highlighter->find('Bar', false)
                 ->highlight([255, 0, 0], 3);
}

# Save image to jpeg
imagejpeg($highlighter->getImage(), "annotated.jpg");

About

Find and highlight Text in Images using Google Cloud Vision API

License:The Unlicense


Languages

Language:PHP 100.0%