<?php

/**
 *
 * @copyright  2021-2022 mcpalo.com
 * @version    2
 * @link       http://www.mcpalo.com
 */

require_once 'sendhttp.php';
require_once 'filemimetype.php';

function scantext($login, $password, $file, $lang='eng', $psm='3', $out='txt', $output='ocr.txt', $params=false) {
	$curl = 'https://tesseractor.com/api/v1/scantext' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);

	$args = array(
		'lang'		=> $lang,
		'psm'		=> $psm,
		'out'		=> $out,
	);

	$args = array_merge($args, $params);

	$files=array('file' => array('name' => basename($file), 'tmp_name' => $file, 'type' => file_mime_type($file)));

	$response=sendpost($curl, $args, $files);

	if (!$response or $response[0] != 200) {
		return false;
	}

	return @file_put_contents($output, $response[2]);
}
