API Documentation
API documentation for different kind of applciation code base in order to serve OCR programmatically.
API documentation for different kind of applciation code base in order to serve OCR programmatically.
POST https://www.imgocr.com/api/imgocr_get_text
Parameter | Type | Description |
---|---|---|
api_key | string | Your API key |
image | string (base64 encoded) | Base64 encoded image file |
Successful response example:
{
"message": "success",
"text": "OUTPUT_TEXT_HERE"
}
Failed response example:
{
"message": "fail",
"error": "ERROR_MESSAGE_HERE"
}
<?php
function sendPostRequest($url, $filePath) {
// Initialize cURL session
$ch = curl_init();
// Prepare the file for upload
$fileData = base64_encode(file_get_contents($filePath));
// Prepare the POST fields
$postData = [
'api_key' => 'API_KEY_STRING_HERE',
'image' => $fileData
];
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Execute the request
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo 'cURL error: ' . curl_error($ch);
} else {
echo $response;
}
// Close cURL session
curl_close($ch);
}
// Usage example
$url = 'https://www.imgocr.com/api/imgocr_get_text';
$filePath = 'test (2).png';
// Run the function
sendPostRequest($url, $filePath);
?>
import requests
import base64
def send_post_request(url, file_path):
with open(file_path, 'rb') as file:
file_data = base64.b64encode(file.read()).decode('utf-8')
post_data = {
'api_key': 'API_KEY_STRING_HERE',
'image': file_data
}
response = requests.post(url, data=post_data, verify=False)
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code}")
# Usage example
url = 'https://www.imgocr.com/api/imgocr_get_text'
file_path = 'test (2).png'
send_post_request(url, file_path)
const axios = require('axios');
const fs = require('fs');
async function sendPostRequest(url, filePath) {
const fileData = fs.readFileSync(filePath, { encoding: 'base64' });
const postData = {
api_key: 'API_KEY_STRING_HERE',
image: fileData
};
try {
const response = await axios.post(url, postData, { httpsAgent: new require('https').Agent({ rejectUnauthorized: false }) });
console.log(response.data);
} catch (error) {
console.error(error);
}
}
// Usage example
const url = 'https://www.imgocr.com/api/imgocr_get_text';
const filePath = 'test (2).png';
sendPostRequest(url, filePath);
curl -X POST https://www.imgocr.com/api/imgocr_get_text \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "api_key=API_KEY_STRING_HERE&image=$(base64 -w 0 test\ \(2\).png)"
If you have any issue while using image to text AI OCR API, we encourage you to Contact Webmaster quickly. We love to fix and enhance user experience for you.