Image Text Translation API Endpoint

Version 2.197 (Release Notes ↗)

Description

The img-translate endpoint allows developers to translate visible text inside images across 11+ supported languages while preserving the original layout and design. It works by intelligently detecting and replacing text within an image using deep OCR + translation models, without altering the image's background, fonts, or structure.

This endpoint is ideal for localizing posters, screenshots, digital signage, and UI assets with embedded multilingual content. All text replacement occurs inline, ensuring the final result looks natural and pixel-consistent with the original design. A typical inline image translation from English to French would look like the following:

Original English Text
Original English Text
Translated French Text
Translated French Text

You may also pass src_lang=auto to auto-detect the source language using built-in language classifier. Advanced options include inline term definition, sensitive content masking, and subject-aware translation strategies.

Supported Languages

Below is the full list of supported source and target languages (along with language codes):

Source Languages

  • English — en
  • Korean — ko
  • Japanese — ja
  • Chinese (Simplified) — zh
  • Russian — ru
  • Spanish — es
  • French — fr
  • Portuguese — pt
  • Italian — it
  • German — de
  • Vietnamese — vi

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.
  • Translation accuracy may vary depending on font size, contrast, and alignment.
  • Best results are obtained with high-resolution inputs (above 720p).
  • Ensure either src_lang is set to en.

To start using this endpoint, obtain your API Key from the PixLab Console ↗ and make a POST request to the img-translate endpoint with your source image and desired language pair.

Consider pairing this endpoint with the TXT-REMOVE API for cleaning image text regions before translation, BG-REMOVE for full backgrounds removal from images. or OCR for raw text extraction.

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.
src_lang String The source language can be specified using its full English name (e.g., english) or its language code (e.g., en). Providing the source language improves the stability of the translation. If the original image's language is unknown, setting this to "auto" will enable automatic detection.
dst_lang String The desired language for the image text translation. You can specify the full English name (e.g., arabic) or the language code (e.g., ar). Providing the source language enhances translation accuracy. If the original image's language is unknown, use "auto" for automatic detection.

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).

POST Request Body

This section details the requirements for using a POST request instead of a simple GET request.

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 ↓ on how to do so.

HTTP Response

application/json

By default, the inline image translation API endpoint always returns a JSON Object 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 ↗. if one the other side, 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 output image data.
extension String Extension such as jpeg of the 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 img-translate endpoint allows developers to translate visible text inside
# images across 11+ supported languages while preserving the original layout and design.
#
# 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')  # The local image we are going to translate text from
    },
    data={
        'src_lang': 'en', # The original text language within the image.
        'dst_lang': 'ar', # Target language (i.e arabic) we want translate to.
        'key': 'PIXLAB_API_KEY'  # PixLab API Key - Get yours from https://console.pixlab.io/
    }
)
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