This API provides services to automatically correct image orientation issues and ensure text is displayed correctly.
URL: /api/correct
Method: POST
Description: Analyzes and corrects the orientation of an image to ensure text is properly oriented.
| Parameter | Type | Description | Required |
|---|---|---|---|
| image | String | Base64-encoded image data | Yes |
| format | String | Image format (jpg, png) | Yes |
{
"finalImage": "base64_encoded_corrected_image",
"portraitImage": "base64_encoded_portrait_image",
"wasLandscape": true|false,
"wasUpsideDown": true|false,
"corrections": "Description of corrections made"
}
curl -X POST \
'http://localhost:8080/api/correct' \
-H 'Content-Type: application/json' \
-d '{
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
"format": "jpg"
}'
// Convert file to base64
function getBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
// Extract the base64 string from data URL
const base64String = reader.result.split(',')[1];
resolve(base64String);
};
reader.onerror = error => reject(error);
});
}
// Send image for correction
async function correctImageOrientation(imageFile) {
try {
const base64Image = await getBase64(imageFile);
const response = await fetch('http://localhost:8080/api/correct', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
image: base64Image,
format: imageFile.name.split('.').pop().toLowerCase()
}),
});
return await response.json();
} catch (error) {
console.error('Error:', error);
}
}
If the image is determined to be in landscape orientation (width > height), the system will analyze the text orientation and rotate the image to portrait mode while maintaining proper text orientation.
Using OCR technology, the system determines if text in a portrait image appears upside down. This is done by comparing OCR confidence scores between the original image and a 180° rotated version.
If text is determined to be upside down, the image is rotated 180° to correct the orientation. The system ensures text is properly oriented for reading from top to bottom.
This API can be integrated with: