API Endpoint Access URL
https://api.pixlab.io/imgtranslate
Get Your API Key & Try Image Text Translation ↗Description
The Image Text Translation API (IMG-TRANSLATE) lets developers translate text inside images while preserving the original image layout. The endpoint detects visible text regions, translates each detected text crop from source_lang to target_lang, removes the original text region, and renders the translated text back into the image.
Use this OCR image translation API to localize screenshots, posters, menus, product images, UI mockups, digital signage, comics, and marketing assets that contain embedded text. The pipeline combines text detection, OCR-style cropping, machine translation, background inpainting, and text rendering so the final output remains an image instead of plain extracted text. A typical inline image translation from English to French looks like the following:
The request must include an uploaded image file, your PixLab API key, a source_lang value, and a target_lang value. Set source_lang=auto when you want the translation model to infer the source language from the detected image text. Optional styling hints let you influence the rendered text size, color, and font.
Supported Languages
Pass either a common language name such as English, French, or Arabic, or a common language code such as en, fr, or ar. The implementation forwards the values to the translation model as source_lang and target_lang. The following languages are good starting points for production integrations:
Common Source Languages
- Auto-detect —
auto - English —
en - Korean —
ko - Arabic —
ar - Japanese —
ja - Chinese (Simplified) —
zh - Russian —
ru - Spanish —
es - French —
fr - Portuguese —
pt - Italian —
it - German —
de - Vietnamese —
vi
Common Target Languages
- English —
en - Korean —
ko - Arabic —
ar - Japanese —
ja - Chinese (Simplified) —
zh - Russian —
ru - Spanish —
es - French —
fr - Portuguese —
pt - Italian —
it - Vietnamese —
vi - Malay —
ms - Thai —
th - Indonesian —
id
Best Practices & Limitations
- Only translate content you own or have rights to localize. Avoid unauthorized translation of copyrighted content.
- Use clear, high-resolution images with readable text, good contrast, and minimal blur.
- Set
source_lang=autofor unknown source text, or pass a known language name/code for more stable translation. - Set
target_langto the language you want rendered back into the image, for exampleEnglish,French,Arabic, orJapanese. - Use
font-size,font-color, andfont-nameonly as rendering hints. The API still fits translated text inside detected regions.
To start using this endpoint, obtain your API Key from the
PixLab Console ↗ and make a POST request to the imgtranslate endpoint with your source image and desired language pair.
Consider pairing this endpoint with the TXT-REMOVE API for removing unwanted text or permitted watermarks, BG-REMOVE for full image background removal, or OCR for raw text extraction without rendering translated text back into the image.
HTTP Methods
POST
HTTP Parameters
Required
| Fields | Type | Description |
|---|---|---|
key |
String | Your PixLab API Key ↗. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
file |
File | The input image containing the visible text to translate. Send it as a multipart/form-data file upload. JPG, JPEG, PNG, and WebP inputs are recommended. |
source_lang |
String | The language of the original text inside the image. Use a language name such as English, a code such as en, or auto when the source language is unknown. |
target_lang |
String | The language to render back into the image. Use a language name such as Arabic, French, or Japanese, or a common language code such as ar, fr, or ja. |
Optional
| Fields | Type | Description |
|---|---|---|
blob |
Boolean |
By default, this API endpoint always returns a JSON Object (see Response Details ↓) containing the BASE64 encoded image output or a direct link to the output image stored in your private AWS S3 bucket if you've already connected your S3 storage credentials from the PixLab Console ↗. However, if this parameter
is set to true, the raw image binary content is returned instead (see the Code Sample section for implementation details).
|
font-size |
Integer | Optional rendering hint for translated text size. If omitted, the API estimates a readable size from each detected text region. |
font-color |
String | Optional rendering hint for translated text color. Use a CSS color name or hex color such as #111111. If omitted, the API selects black or white based on local background brightness. |
font-name |
String | Optional rendering hint for the font file used by the renderer. Defaults to arial.ttf when omitted or unavailable. |
POST Request Body
Use a POST request with a multipart file upload. The public endpoint accepts the image as file and reads the language pair from source_lang and target_lang.
Allowed Content-Types:
multipart/form-data
Submit a multipart/form-data POST request to directly upload your image from your app. Refer to the code samples section below ↓ for working examples in Python, JavaScript, PHP, and Ruby.
HTTP Response
application/json
By default, the image text translation API endpoint returns a JSON Object containing the translated image as BASE64 encoded image output or a direct link to the translated image stored in your private AWS S3 bucket if you've already connected your S3 storage credentials from the PixLab Console ↗. If the
blob parameter (documented above) is set to true, the raw image binary content is returned instead.
| Fields | Type | Description |
|---|---|---|
status |
Integer | HTTP 200 indicates success. Any other code indicates failure. |
imgData |
Base64 Data | Base64 encoded string of the translated output image. |
extension |
String | Extension such as png, jpeg, or webp of the translated output image. |
link |
URL | Optionally, a direct link to the output image (instead of the imgData field) stored on your own AWS S3 bucket if you already connected your AWS S3 credentials from the PixLab Console ↗. |
error |
String |
Error description when status != 200.
|
blob |
BLOB | Optionally, the image blob data is returned instead of this JSON object if the blob parameter (documented above) is set to true. |
Code Samples
import requests
import json
import base64
import os
# The Image Text Translation API detects visible text inside an image,
# translates it, and renders the translated text back into the image.
#
# Refer to the official documentation at: https://pixlab.io/endpoints/image-text-translate for the API reference guide and more code samples.
# Use POST to upload the image directly from your local folder.
req = requests.post(
'https://api.pixlab.io/imgtranslate',
files={
'file': open('./local_image.png', 'rb') # Required input image.
},
data={
'source_lang': 'English', # Required. Use 'auto' when the source language is unknown.
'target_lang': 'French', # Required. Language to render back into the image.
'key': 'PIXLAB_API_KEY', # Required. Get yours from https://console.pixlab.io/
# Optional rendering hints supported by the implementation:
# 'font-size': 24,
# 'font-color': '#111111',
# 'font-name': 'arial.ttf'
}
)
reply = req.json()
if reply['status'] != 200:
print(reply['error'])
else:
imgData = reply['imgData'] # Base64 encoding of the output image
extension = reply['extension'] # File extension (e.g., 'png', 'jpeg')
# Decode base64 and save to disk
try:
img_bytes = base64.b64decode(imgData)
output_filename = f"output_image.{extension}"
with open(output_filename, "wb") as f:
f.write(img_bytes)
print(f"Inline Translated Image saved to: {output_filename}")
except Exception as e:
print(f"Error saving output image: {e}")
// The Image Text Translation API detects visible text inside an image,
// translates it, and renders the translated text back into the image.
//
// Refer to the official documentation at: https://pixlab.io/endpoints/image-text-translate for the API reference guide and more code samples.
// Use POST to upload the image directly from your local folder.
async function translateImage() {
const formData = new FormData();
formData.append('file', document.querySelector('input[type="file"]').files[0]); // Required input image.
formData.append('source_lang', 'English'); // Required. Use 'auto' when unknown.
formData.append('target_lang', 'French'); // Required. Language to render back into the image.
formData.append('key', 'PIXLAB_API_KEY'); // Required. Get yours from https://console.pixlab.io/
// Optional rendering hints supported by the implementation:
// formData.append('font-size', '24');
// formData.append('font-color', '#111111');
// formData.append('font-name', 'arial.ttf');
try {
const response = await fetch('https://api.pixlab.io/imgtranslate', {
method: 'POST',
body: formData
});
const reply = await response.json();
if (reply.status !== 200) {
console.error(reply.error);
} else {
const imgData = reply.imgData; // Base64 encoding of the output image
const extension = reply.extension; // File extension (e.g., 'png', 'jpeg')
// Decode base64 and save to disk
try {
const img_bytes = atob(imgData); //browser built in decoder
const output_filename = `output_image.${extension}`;
const uint8Array = new Uint8Array(img_bytes.length);
for (let i = 0; i < img_bytes.length; i++) {
uint8Array[i] = img_bytes.charCodeAt(i);
}
const blob = new Blob([uint8Array], { type: `image/${extension}` });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = output_filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
console.log(`Inline Translated Image saved to: ${output_filename}`);
} catch (e) {
console.error(`Error saving output image: ${e}`);
}
}
} catch (error) {
console.error(error);
}
}
// Example usage (assuming you have a file input with id "imageUpload")
document.addEventListener('DOMContentLoaded', () => {
const fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.addEventListener('change', translateImage);
document.body.appendChild(fileInput);
});
<?php
# The Image Text Translation API detects visible text inside an image,
# translates it, and renders the translated text back into the image.
#
# Refer to the official documentation at: https://pixlab.io/endpoints/image-text-translate for the API reference guide and more code samples.
# Use POST to upload the image directly from your local folder.
$url = 'https://api.pixlab.io/imgtranslate';
$apiKey = 'PIXLAB_API_KEY'; // Replace with your PixLab API Key - Get yours from https://console.pixlab.io/
$imagePath = './local_image.png'; // Required input image.
$sourceLang = 'English'; // Required. Use 'auto' when the source language is unknown.
$targetLang = 'French'; // Required. Language to render back into the image.
$postData = array(
'source_lang' => $sourceLang,
'target_lang' => $targetLang,
'key' => $apiKey,
// Optional rendering hints supported by the implementation:
// 'font-size' => 24,
// 'font-color' => '#111111',
// 'font-name' => 'arial.ttf'
);
$file = new CURLFile(realpath($imagePath), mime_content_type($imagePath), 'file');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array_merge($postData, array('file' => $file)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data"));
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
exit;
}
curl_close($ch);
$reply = json_decode($response, true);
if ($reply['status'] != 200) {
echo $reply['error'];
} else {
$imgData = $reply['imgData']; // Base64 encoding of the output image
$extension = $reply['extension']; // File extension (e.g., 'png', 'jpeg')
// Decode base64 and save to disk
try {
$imgBytes = base64_decode($imgData);
$outputFilename = "output_image.{$extension}";
file_put_contents($outputFilename, $imgBytes);
echo "Inline Translated Image saved to: {$outputFilename}";
} catch (Exception $e) {
echo "Error saving output image: " . $e->getMessage();
}
}
require 'net/http'
require 'json'
require 'base64'
require 'uri'
# The Image Text Translation API detects visible text inside an image,
# translates it, and renders the translated text back into the image.
#
# Refer to the official documentation at: https://pixlab.io/endpoints/image-text-translate for the API reference guide and more code samples.
# Use POST to upload the image directly from your local folder.
uri = URI('https://api.pixlab.io/imgtranslate')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.path)
form_data = {
'file' => File.open('./local_image.png'), # Required input image.
'source_lang' => 'English', # Required. Use 'auto' when unknown.
'target_lang' => 'French', # Required. Language to render back into the image.
'key' => 'PIXLAB_API_KEY', # Required. Get yours from https://console.pixlab.io/
# Optional rendering hints supported by the implementation:
# 'font-size' => '24',
# 'font-color' => '#111111',
# 'font-name' => 'arial.ttf'
}
request.set_form(form_data, 'multipart/form-data')
response = http.request(request)
reply = JSON.parse(response.body)
if reply['status'] != 200
puts reply['error']
else
img_data = reply['imgData'] # Base64 encoding of the output image
extension = reply['extension'] # File extension (e.g., 'png', 'jpeg')
# Decode base64 and save to disk
begin
img_bytes = Base64.decode64(img_data)
output_filename = "output_image.#{extension}"
File.open(output_filename, 'wb') do |f|
f.write(img_bytes)
end
puts "Inline Translated Image saved to: #{output_filename}"
rescue => e
puts "Error saving output image: #{e}"
end
end
Similar API Endpoints
tagimg, nsfw, describe, docscan, llm-parse, docscan, text-watermark-remove, bg-remove, facelookup ↗, faceverify ↗, img-embed, query