Last active
June 6, 2022 16:44
-
-
Save iNawaR1/b04b20bdabdb12db33f11d54b9326cf0 to your computer and use it in GitHub Desktop.
Idea from (hamoudi) on Tele. this is API script to get any text from image !!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(0); | |
$image = new CURLFILE("image.png"); // image location (Host the image using any online image hoster) | |
$api = 'API Key Here'; // go to https://ocr.space and make your free api key and put it in the $api section (: | |
$language = 'ar'; // use *ar* for convert arabic text, use *en* for convert englih text | |
$mode = ( $language == 'ar' ) ? $lang = 'ara' : 'eng'; | |
Function ocr($image, $api, $mode) | |
{ | |
$url = 'https://api8.ocr.space/parse/image'; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
$headers = array(); | |
$headers[] = 'accept: application/json, text/javascript, */*; q=0.01'; | |
$headers[] = 'content-type: multipart/form-data'; | |
$headers[] = 'origin: https://ocr.space'; | |
$headers[] = 'referer: https://ocr.space/'; | |
$headers[] = 'apikey: ' . $api; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // u can replace these chose to your choise user-agent | |
curl_setopt($ch, CURLOPT_POSTFIELDS, ["file" => $image, "url"=> "null", "language"=> $mode, "isOverlayRequired"=> "true", "FileType"=> ".Auto", "IsCreateSearchablePDF"=> "false", "isSearchablePdfHideTextLayer"=> "true", "detectOrientation"=> "false", "isTable"=> "false", "scale"=> "true", "OCREngine"=> "1", "detectCheckbox"=> "false", "checkboxTemplate"=> "0"]); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
echo $response; | |
} | |
echo ocr($image, $api, $mode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment