janrop/highlight-text-in-image

该软件包最新版本(v1.0)没有提供许可证信息。

使用 Google Cloud Vision API 查找并突出显示图像中的文本

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

This package is not auto-updated.

Last update: 2023-09-16 22:00:55 UTC


README

允许您使用 Google Cloud Vision API 检查并突出显示图像中的字符串

安装

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

在使用之前,您需要下载一个 Google 身份验证详细信息 .json 文件 并将其引用在 GOOGLE_APPLICATION_CREDENTIALS 环境变量中

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

使用方法

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