I need to ocr Characters like öäü, so i need to set language to german.
In the php api demo script i found this GuzzleHttp Part:
$r = $client->request(‘POST’, ‘https://api.ocr.space/parse/image ’,[
‘headers’ => [‘apiKey’ => ‘helloworld’],
‘multipart’ => [
[
‘name’ => ‘file’,
‘contents’ => $fileData
]
]
], [‘file’ => $fileData]);
$response = json_decode($r->getBody(),true);
Where there i have to add the language? =) Thank you.
Update: I think it´s not possible to send image and post fiels at the same time with this method, but i was able to find a solution that works perfectly with curl.
admin
August 3, 2018, 10:08pm
2
Here is a new PHP code snippet. The code is from an OCR.space user, posted here with permission:
Problem:
cURL call to API ocr.space with PHP not going through?
Answer:
Problems were:
do not use json_encode()
change content type to Content-Type:multipart/form-data
set quotation marks around "false"
and "true"
values.
This works now:
$imageurl = "https://...imageurl.jpg";
$data = array(
"language" => "ger",
"isOverlayRequired" => "false",
"detectOrientation" => "true",
"scale" => "true",
"filetype" => 'JPG',
"url" => $imageurl,
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://api.ocr.space/parse/image",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => array('Content-Type:multipart/form-data', 'apikey:apikey:MYAPIKEY'),
CURLOPT_POSTFIELDS => $data,
));
$result = curl_exec($ch);
curl_close($ch);
$result_array = json_decode($result);
if(!empty($result_array->ErrorMessage))
{
// catch errors https://docs.mathpix.com/#errors
echo 'Problem: '.$result_array->ErrorMessage[0];
}
else
{
// recognized text
$ocrresult = $result_array->ParsedResults[0]->ParsedText;
}
See also this C# post “No file uploaded or URL provided” when calling ocr.space API
Did you find any solution for this?