Image Text Translation API Endpoint

Version 2.197 (Release Notes ↗)

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:

Original Image With English Text
Original image with English text before inline translation
Translated Image With French Text
Image after translating embedded English text into French

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=auto for unknown source text, or pass a known language name/code for more stable translation.
  • Set target_lang to the language you want rendered back into the image, for example English, French, Arabic, or Japanese.
  • Use font-size, font-color, and font-name only 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}")
← Return to API Endpoint Listing