Skip to content

Instantly share code, notes, and snippets.

@symisc
Created March 13, 2021 00:32
Show Gist options
  • Save symisc/ce43b075da7e91b05f9dee954ffbcfce to your computer and use it in GitHub Desktop.
Save symisc/ce43b075da7e91b05f9dee954ffbcfce to your computer and use it in GitHub Desktop.
Given an image with human readable characters. Detect input language & extract text content from there using the PixLab API - https://pixlab.io/cmd?id=ocr
<?php
/*
* PixLab PHP Client which is just a single class PHP file without any dependency that you can get from Github
* https://github.com/symisc/pixlab-php
*/
require_once "pixlab.php";
# Given an image with human readable characters. Detect input language & extract text content from there.
# https://pixlab.io/cmd?id=ocr for additional information.
/* Target image with human readable text input */
$img = 'http://quotesten.com/wp-content/uploads/2016/06/Confucius-Quote.jpg';
# Your PixLab API Key. Get yours from https://pixlab.io/dashboard
$key = 'PIXLAB_API_KEY';
/* Process */
$pix = new Pixlab($key);
if( !$pix->get('ocr',array('img' => $img, 'orientation' => true, 'nl' => true)) ){
echo $pix->get_error_message()."\n";
die;
}
echo "Input language: ".$pix->json->lang;
echo "\nText Output: ".$pix->json->output."\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment