Base64 Image
All AIGEN image-based APIs accept images as Base64-encoded strings in the request body. The Base64 string must contain only the encoded data — without the data: URI prefix.
Supported Formats
| Format | Extensions | Notes |
|---|---|---|
| JPEG | .jpg, .jpeg | Most common, recommended |
| PNG | .png | Supports transparency |
.pdf | Multi-page supported on select endpoints |
Removing the Data URI Prefix
When converting an image to Base64 (e.g., from a file input in a browser), the result often includes a prefix like data:image/jpeg;base64,. You must remove this prefix before sending to the API.
- JavaScript
- Python
- PHP
- cURL
// Browser file input
const file = document.querySelector("input[type=file]").files[0];
const reader = new FileReader();
reader.onload = () => {
// Remove the "data:image/...;base64," prefix
const base64 = reader.result.split(",")[1];
console.log(base64); // Ready to send to API
};
reader.readAsDataURL(file);
import base64
# From file
with open("image.jpg", "rb") as f:
base64_string = base64.b64encode(f.read()).decode("utf-8")
# Ready to send to API
print(base64_string)
<?php
// From file
$base64_string = base64_encode(file_get_contents("image.jpg"));
// Ready to send to API
echo $base64_string;
?>
# Encode image file and send directly
BASE64=$(base64 -i image.jpg)
curl -X POST 'https://api.aigen.online/aiscript/idcard/v3' \
-H 'X-AIGEN-KEY: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d "{\"image\": \"$BASE64\"}"
Image Size Guidelines
- Minimum resolution: 112 x 112 pixels (varies by endpoint)
- Maximum file size: Varies by endpoint
- Best practice: Use images between 300 DPI and 600 DPI for optimal OCR accuracy
tip
For higher accuracy, ensure the document fills most of the image frame and is well-lit without glare or shadows.
Dev Tool
Use AIGEN's online tool to quickly encode/decode Base64 images: