图片翻译 Image Translation
上传图片,通过高精度 OCR 识别图中文字并翻译为目标语言。支持多种图片格式、多语言文字识别、术语库集成以及指定翻译风格。 Upload images for OCR-based text recognition and translation into the target language. Supports multiple image formats, multi-language recognition, glossary integration, and custom translation styles.
快速概览
Quick Facts
端点 Endpoint POST /v1/image/translate
认证方式 Auth Bearer Token
输入方式 Input 文件上传 (multipart) 或 图片 URL (JSON) File upload (multipart) or image URL (JSON)
图片上限 Max Size 20 MB
输出模式 Output Mode 纯文本 / 按区域含坐标 Plain text / By region with coordinates
支持语言 Languages 50+ 语言 50+ languages
请求端点 Endpoint
POST /v1/image/translate
认证 Authentication
Authorization: Bearer {access_token}
请求头 Request Headers
请求头 Header 必填 Required 说明 Description
Authorization required Bearer 认证,格式:Bearer {access_token} Bearer authentication, format: Bearer {access_token}
Content-Type required 文件上传时使用 multipart/form-data;JSON 模式使用 application/json Use multipart/form-data for file upload; application/json for JSON mode
请求参数 Request Parameters
参数 Parameter 类型 Type 必填 Required 说明 Description
image file / string required 图片文件(multipart 上传)或图片 URL(JSON 模式)。最大 20MB。建议分辨率不低于 200 DPI 以获得最佳识别效果。 Image file (multipart) or image URL (JSON). Max 20MB. Recommended at least 200 DPI for best recognition.
target_lang string required 目标翻译语言代码,详见语种列表 Target language code, see Language List
source_lang string optional 图片中文字语言代码。默认自动检测。当已知语言时建议显式指定以提高识别准确度。 Source language code. Auto-detected by default. Specifying it improves accuracy when known.
output_type string optional text — 仅返回纯文本翻译结果(不含位置信息);regions — 按区域返回,每块文本含坐标 bbox 及原文与译文。默认 texttext — plain text only (no position info);regions — per region with bbox, original and translated text. Default text
formality string optional 翻译语气:default(默认)、more(更正式)、less(更随意)。仅特定语言支持,见下方表单性支持表。 Formality: default, more (formal), less (casual). Only supported for certain languages, see formality table below.
glossary_id string optional 关联术语库 ID,翻译时优先采用术语库中的定义 Glossary ID for custom term definitions during translation
preserve_formatting boolean optional 是否保留原文中的换行、空格等格式。默认 false Preserve line breaks and whitespace. Default false
model_type string optional 模型选择:standard(标准,默认)、prefer_quality(高质量,适用于复杂排版) Model: standard (default), prefer_quality (higher quality for complex layouts)
show_billed_characters boolean optional 是否在响应中返回计费字符数。默认 false Return billed character count in response. Default false
表单性支持 Formality Support
以下语言在图片翻译中支持 formality 参数,可控制翻译结果的语气正式程度: The following languages support the formality parameter in image translation to control tone:
语言 Language 语言代码 Code
德语 German DE
法语 French FR
意大利语 Italian IT
西班牙语 Spanish ES
葡萄牙语 Portuguese PT
俄语 Russian RU
日语 Japanese JA
韩语 Korean KO
荷兰语 Dutch NL
波兰语 Polish PL
支持图片格式 Supported Image Formats
格式 Format MIME 类型 MIME Type 说明 Notes
JPEG / JPG image/jpeg最常用格式,推荐质量 80% 以上 Most common, recommended quality > 80%
PNG image/png支持透明通道,适合截图和图标 Supports alpha channel, ideal for screenshots and icons
WebP image/webp高压缩率,同样质量下文件更小 High compression, smaller file size at same quality
BMP image/bmp无压缩位图,文件较大但无质量损失 Uncompressed bitmap, larger files but lossless
TIFF image/tiff常用于文档扫描,支持多页(仅第一页被处理) Common for scanned documents, multi-page (first page only)
PDF(单页) application/pdf仅支持单页 PDF,多页请使用文档翻译 Single-page PDF only; use Document Translation for multi-page
请求示例 Request Examples
cURL — 文件上传 cURL — File Upload
curl -X POST https://api.itranslator.cc/v1/image/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "image=@menu.jpg" \
-F "target_lang=en" \
-F "source_lang=ja" \
-F "output_type=regions" \
-F "formality=more"
Copy
cURL — URL 模式 cURL — URL Mode
curl -X POST https://api.itranslator.cc/v1/image/translate \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"image": "https://example.com/menu.jpg",
"target_lang": "en",
"source_lang": "ja",
"output_type": "text",
"glossary_id": "gl_abc123"
}'
Copy
Python — 文件上传 Python — File Upload
import requests
url = "https://api.itranslator.cc/v1/image/translate"
headers = {"Authorization": f"Bearer {token}"}
with open("menu.jpg", "rb") as img:
resp = requests.post(
url,
headers=headers,
files={"image": img},
data={
"target_lang": "en",
"source_lang": "ja",
"output_type": "regions",
"formality": "more"
}
)
result = resp.json()
for region in result["regions"]:
print(f"{region['source_text']} → {region['translation']}")
Copy
Python — URL 模式 Python — URL Mode
import requests
resp = requests.post(
"https://api.itranslator.cc/v1/image/translate",
headers={
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
},
json={
"image": "https://example.com/sign.jpg",
"target_lang": "zh",
"source_lang": "en",
"output_type": "text",
"show_billed_characters": True
}
)
print(resp.json())
Copy
JavaScript (Node.js) JavaScript (Node.js)
const fs = require("fs");
const form = new FormData();
form.append("image", fs.createReadStream("./menu.jpg"));
form.append("target_lang", "en");
form.append("output_type", "regions");
const resp = await fetch(
"https://api.itranslator.cc/v1/image/translate",
{
method: "POST",
headers: { Authorization: `Bearer ${token}` },
body: form
}
);
const data = await resp.json();
console.log(data);
Copy
Java Java
import java.net.URI;
import java.net.http.*;
// 使用 URL 模式
HttpClient client = HttpClient.newHttpClient();
String json = """
{"image":"https://example.com/menu.jpg","target_lang":"en","output_type":"text"}
""";
HttpRequest req = HttpRequest.newBuilder()
.uri(URI.create("https://api.itranslator.cc/v1/image/translate"))
.header("Authorization", "Bearer " + token)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<String> resp = client.send(req,
HttpResponse.BodyHandlers.ofString());
System.out.println(resp.body());
Copy
响应字段说明 Response Fields
字段 Field 类型 Type 说明 Description
source_lang string 检测或指定的源语言代码 Detected or specified source language code
target_lang string 目标翻译语言代码 Target language code
full_text string 完整翻译后的纯文本(output_type=text 时为主要输出) Full translated text (main output when output_type=text)
regions array 区域数组(仅 output_type=regions),每项含 bbox、source_text、translation、confidence Region array (output_type=regions only), each with bbox, source_text, translation, confidence
billed_characters integer 计费字符数(仅 show_billed_characters=true 时返回) Billed character count (only when show_billed_characters=true)
detected_source_lang string 自动检测到的源语言(source_lang 未指定时返回) Auto-detected source language (returned when source_lang not specified)
model_type_used string 实际使用的翻译模型 The translation model actually used
processing_time_ms integer 处理耗时(毫秒) Processing time in milliseconds
响应示例 Response Examples
示例 1:output_type=text(默认) Example 1: output_type=text (default)
{
"source_lang": "ja",
"target_lang": "en",
"detected_source_lang": "ja",
"full_text": "Assorted Sashimi $28.00\nToday's Special - Grilled Salmon $18.50",
"billed_characters": 48,
"model_type_used": "standard",
"processing_time_ms": 320
}
示例 2:output_type=regions(含位置信息) Example 2: output_type=regions (with position)
{
"source_lang": "ja",
"target_lang": "en",
"regions": [
{
"bbox": { "x": 120, "y": 45, "w": 200, "h": 30 },
"source_text": "刺身盛り合わせ",
"translation": "Assorted Sashimi",
"confidence": 0.98
},
{
"bbox": { "x": 380, "y": 45, "w": 160, "h": 30 },
"source_text": "$28.00",
"translation": "$28.00",
"confidence": 1.00
},
{
"bbox": { "x": 120, "y": 85, "w": 300, "h": 30 },
"source_text": "本日のおすすめ — 焼き鮭",
"translation": "Today's Special — Grilled Salmon",
"confidence": 0.95
},
{
"bbox": { "x": 420, "y": 85, "w": 120, "h": 30 },
"source_text": "$18.50",
"translation": "$18.50",
"confidence": 1.00
}
],
"full_text": "Assorted Sashimi $28.00\nToday's Special — Grilled Salmon $18.50",
"processing_time_ms": 380
}
示例 3:含术语库 + 表单性 Example 3: With Glossary + Formality
{
"source_lang": "zh",
"target_lang": "ja",
"regions": [
{
"bbox": { "x": 50, "y": 30, "w": 180, "h": 28 },
"source_text": "欢迎光临",
"translation": "いらっしゃいませ",
"confidence": 0.99
},
{
"bbox": { "x": 50, "y": 70, "w": 220, "h": 28 },
"source_text": "新品上市 — 抹茶拿铁",
"translation": "新発売 — 抹茶ラテ(※用語集適用)",
"confidence": 0.97
}
],
"full_text": "いらっしゃいませ\n新発売 — 抹茶ラテ(※用語集適用)",
"model_type_used": "prefer_quality",
"processing_time_ms": 520
}
错误码 Error Codes
Status 错误码 Code 说明 Description
400 UNSUPPORTED_IMAGE 不支持的图片格式或图片已损坏 Unsupported or corrupted image format
400 IMAGE_TOO_LARGE 图片超过 20MB 限制 Image exceeds 20MB limit
400 NO_TEXT_DETECTED 图片中未检测到可识别的文字 No recognizable text detected in image
400 INVALID_IMAGE_URL 图片 URL 无效、无法访问或超时 Invalid, inaccessible or timed-out image URL
400 INVALID_LANGUAGE 不支持的语言代码 Unsupported language code
401 UNAUTHORIZED 缺少或无效的 Access Token Missing or invalid access token
403 FORBIDDEN 无权访问该资源或配额已耗尽 Access denied or quota exceeded
413 PAYLOAD_TOO_LARGE 请求体超过服务器限制 Request body too large
429 RATE_LIMITED 请求频率超限,请降低并发数 Rate limit exceeded, reduce concurrency
456 GLOSSARY_NOT_FOUND 指定的术语库不存在或已被删除 Specified glossary not found or deleted
500 INTERNAL_ERROR 服务器内部错误,请稍后重试 Internal server error, try again later
503 SERVICE_UNAVAILABLE 服务暂时不可用,请稍后重试 Service temporarily unavailable
最佳实践 Best Practices
图片质量 :确保图片清晰,分辨率不低于 200 DPI。模糊或低光照的图片会显著降低识别准确率。
Image Quality : Ensure images are clear with at least 200 DPI resolution. Blurry or low-light images significantly reduce recognition accuracy.
指定源语言 :当已知图片文字语言时,建议通过 source_lang 显式指定,避免自动检测带来的延迟和误判。
Specify Source Language : Always specify source_lang when known to avoid auto-detection delay and misidentification.
选择合适的 output_type :如果只需要翻译文本,使用 text 模式更快;如果需要定位还原到图片,使用 regions 模式获取坐标。
Choose Output Type : Use text mode for plain translated text (faster); use regions mode when you need coordinates for overlay.
结合术语库 :对特定领域(医疗、法律、游戏等)的图片翻译,需要传入 glossary_id 以确保专业术语的翻译一致性。
Use Glossary : For domain-specific images (medical, legal, gaming, etc.), pass glossary_id to ensure consistent professional terminology.
大图预处理 :超过 10MB 的图片建议先压缩到合适大小再上传,可显著减少网络传输时间和请求延迟。
Pre-process Large Images : Compress images over 10MB before upload to reduce network latency and request time.
错误重试 :对于 429(频率限制)和 5xx(服务器错误),建议实现指数退避重试策略。
Retry Strategy : Implement exponential backoff for 429 (rate limit) and 5xx (server errors) responses.
常见应用场景 Common Use Cases
场景 Scenario 说明 Description
菜单翻译 Menu Translation 拍摄菜单即可获得翻译,建议使用 regions 模式将翻译叠加到图片原位 Snap a menu for translation; use regions mode to overlay translations in place
路标/指示牌 Signage & Signboards 出国旅行时拍摄路标、指示牌快速获取翻译 Quick translation of street signs and direction boards while traveling
产品标签 Product Labels 跨境电商场景下翻译商品成分表、说明书标签,可配合术语库使用 Translate ingredient lists and product labels for e-commerce, works with glossary
漫画/图文 Comics & Manga 翻译漫画中的对话气泡,regions 模式下可按区域逐条获取 Translate speech bubbles in comics; regions provide text by bubble
截屏翻译 Screenshot Translation 翻译应用、游戏或网页截图中出现的文字,适用于本地化测试 Translate text in app, game or web screenshots for localization testing
与 OCR 接口的区别 Difference from OCR API
图片翻译 API Image Translate API OCR API
功能 Function 识别 + 翻译 Recognize + Translate 仅识别文本,不做翻译 Text recognition only, no translation
输出 Output 翻译后的目标语言文本 Translated text in target language 图片中的原始文字 Original text from the image
适用 Use Case 直接需要翻译结果的场景 When translated output is needed directly 需要原始文本做后续处理(NLP、搜索、归档等) When original text is needed for downstream processing (NLP, search, archiving)
图片上限 Max Size 20 MB 10 MB
使用说明
Notes
文件上传使用 multipart/form-data 编码,Content-Type 请勿手动设置,让 HTTP 客户端自动生成。
Use multipart/form-data encoding; let the HTTP client auto-generate Content-Type.
大文件建议先压缩或使用异步任务模式,避免请求超时。单次请求超时时间为 30 秒。
For large files, compress or use async task mode to avoid timeouts. Request timeout is 30 seconds.
请勿在客户端代码中暴露 Access Token,建议通过后端代理调用。
Do not expose your Access Token in client-side code; use a backend proxy.
如果图片包含密集文字(如文档扫描件),建议使用 model_type=prefer_quality 以获得更好效果。
For dense text images (e.g., scanned documents), use model_type=prefer_quality for better results.