janrop/highlight-text-in-image

There is no license information available for the latest version (v1.0) of this package.

Find and highlight Text in Images using Google Cloud Vision API

v1.0 2017-06-23 09:34 UTC

This package is not auto-updated.

Last update: 2022-06-25 15:31:42 UTC


README

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");