manga-image-translator README

The project's README from github.com/zyddnys/manga-image-translator. As one markdown file: README.md.

Manga/Image Translator (English Readme)

Last Updated: 2025/05/10

Commit activity Lines of code License Contributors Discord

One-click translation of text in various images
中文说明 | Changelog
Welcome to join our Discord https://discord.gg/Ak8APNy4vb

This project aims to translate images that are unlikely to be professionally translated, such as comics/images on various group chats and image boards, making it possible for Japanese novices like me to understand the content. It mainly supports Japanese, but also supports Simplified and Traditional Chinese, English and 20 other minor languages. Supports image repair (text removal) and typesetting. This project is v2 of Qiú wén zhuǎn yì zhì.

Note: This project is still in the early stages of development and has many shortcomings. We need your help to improve it!

📂 Directory

Showcase

The following examples may not be frequently updated and may not represent the effect of the current main branch version.

Original Image Translated Image
佐藤さんは知っていた - 猫麦
(Source @09ra_19ra)
Output
(Mask)
Gris finds out she's of royal blood - VERTI
(Source @VERTIGRIS_ART)
Output
--detector ctd (Mask)
陰キャお嬢様の新学期🏫📔🌸 (#3) - ひづき夜宵🎀💜
(Source @hiduki_yayoi)
Output
--translator none (Mask)
幼なじみの高校デビューの癖がすごい (#1) - 神吉李花☪️🐧
(Source @rikak)
Output
(Mask)

Online Version

Official demo site (maintained by zyddnys): https://touhou.ai/imgtrans/
Browser script (maintained by QiroNT): https://greasyfork.org/scripts/437569

Rust Version

Manga Image Translator Rust may be easier to setup as its a compiled binary

Installation

Local Setup

# First, ensure you have Python 3.10 or later installed on your machine
# The very latest version of Python might not be compatible with some PyTorch libraries yet
$ python --version
Python 3.10.6

# Clone this repository
$ git clone https://github.com/zyddnys/manga-image-translator.git

# Create a venv (optional, but recommended)
$ python -m venv venv

# Activate the venv
$ source venv/bin/activate

# If you want to use the --use-gpu option, please visit https://pytorch.org/get-started/locally/ to install PyTorch, which needs to correspond to your CUDA version.
# If you did not use venv to create a virtual environment, you need to add --upgrade --force-reinstall to the pip command to overwrite the currently installed PyTorch version.

# Install dependencies
$ pip install -r requirements.txt

Models will be automatically downloaded to the ./models directory at runtime.

Notes for Windows Users:

Please install Microsoft C++ Build Tools (Download, Instructions) before performing the pip install, as some pip dependencies need it to compile. (See #114).

To use CUDA on Windows, install the correct PyTorch version as described on https://pytorch.org/get-started/locally/.

Docker

Requirements:

This project supports Docker, with the image being zyddnys/manga-image-translator:main. This Docker image contains all the dependencies and models required for the project. Please note that this image is quite large (~15GB).

Run Web Server

You can start the Web Server (CPU) using the following command:

Note that you need to add the required environment variables using -e or --env

docker run \
  --name manga_image_translator_cpu \
  -p 5003:5003 \
  --ipc=host \
  --entrypoint python \
  --rm \
  -v /demo/doc/../../result:/app/result \
  -v /demo/doc/../../server/main.py:/app/server/main.py \
  -v /demo/doc/../../server/instance.py:/app/server/instance.py \
  -e OPENAI_API_KEY='' \
  -e OPENAI_API_BASE='' \
  -e OPENAI_MODEL='' \
  zyddnys/manga-image-translator:main \
  server/main.py --verbose --start-instance --host=0.0.0.0 --port=5003

Or use the compose file

Note that you need to add the required environment variables in the file first

docker-compose -f demo/doc/docker-compose-web-with-cpu.yml up

The Web Server starts on port 8000 by default, and the translation results will be saved in the /result folder.

Using Nvidia GPU

To use a supported GPU, please read the Docker section above first. You will need some special dependencies.

You can start the Web Server (GPU) using the following command:

Note that you need to add the required environment variables using -e or --env

docker run \
  --name manga_image_translator_gpu \
  -p 5003:5003 \
  --ipc=host \
  --gpus all \
  --entrypoint python \
  --rm \
  -v /demo/doc/../../result:/app/result \
  -v /demo/doc/../../server/main.py:/app/server/main.py \
  -v /demo/doc/../../server/instance.py:/app/server/instance.py \
  -e OPENAI_API_KEY='' \
  -e OPENAI_API_BASE='' \
  -e OPENAI_MODEL='' \
  -e OPENAI_HTTP_PROXY='' \
  zyddnys/manga-image-translator:main \
  server/main.py --verbose --start-instance --host=0.0.0.0 --port=5003 --use-gpu

Or use the compose file (for Web Server + GPU):

Note that you need to add the required environment variables in the file first

docker-compose -f demo/doc/docker-compose-web-with-gpu.yml up

Use as CLI

To use Docker via CLI (i.e., Batch Mode):

Some translation services require API keys to run, pass them to your docker container as environment variables.

docker run --env="DEEPL_AUTH_KEY=xxx" -v <targetFolder>:/app/<targetFolder> -v <targetFolder>-translated:/app/<targetFolder>-translated  --ipc=host --rm zyddnys/manga-image-translator:main local -i=/app/<targetFolder> <cli flags>

Note: If you need to reference files on your host, you will need to mount the relevant files as volumes into the /app folder inside the container. The CLI paths will need to be the internal Docker path /app/... and not the path on your host.

Build Locally

To build the docker image locally, you can run the following command (you need to have make tool installed on your machine):

make build-image

Then test the built image, run:

Some translation services require API keys to run, pass them to your docker container as environment variables. Add environment variables in the Dockerfile.

make run-web-server

Usage

Local (Batch) Mode

# Replace <path> with the path to your image folder or file.
$ python -m manga_translator local -v -i <path>
# The results can be found in `<path_to_image_folder>-translated`.

Web Mode

Old UI

# Start a web server.
$ cd server
$ python main.py --use-gpu
# The web demo service address is http://127.0.0.1:8000

New UI

Documentation

API Mode

# Start a web server.
$ cd server
$ python main.py --use-gpu
# The API service address is http://127.0.0.1:8001

API Documentation

Read the openapi documentation at: 127.0.0.1:8000/docs

FastAPI-html

Config-help Mode

python -m manga_translator config-help

Options and Configuration Description

Detector:

OCR:

Translator:

Inpainter: lama_large

Colorizer: mc2

Tips to Improve Translation Quality

Command Line Options

Basic Options

-h, --help                     show this help message and exit
-v, --verbose                  print debug messages and save intermediate images in results folder
--attempts ATTEMPTS            Number of attempts when an error occurs. -1 for infinite attempts.
--ignore-errors                Skip images when an error occurs.
--model-dir MODEL_DIR          Model directory (defaults to ./models in the project root)
--use-gpu                      Turns on/off GPU (automatically switches between mps and cuda)
--use-gpu-limited              Turns on/off GPU (excluding offline translators)
--font-path FONT_PATH          Path to the font file
--pre-dict PRE_DICT            Path to the pre-translation replacement dictionary file
--post-dict POST_DICT          Path to the post-translation replacement dictionary file
--kernel-size KERNEL_SIZE      Set the kernel size for the convolution of text erasure area to completely clear residual text
--context-size                 Pages of context are needed for translating the current page. currently, this only applies to openaitranslator. 

Additional Options

Local Mode Options
local                         run in batch translation mode
-i, --input INPUT [INPUT ...] Image folder path (required)
-o, --dest DEST               Destination folder path for translated images (default: '')
-f, --format FORMAT           Output format for the translation. Options: [List OUTPUT_FORMATS here, png,webp,jpg,jpeg,xcf,psd,pdf]
--overwrite                   Overwrite already translated images
--skip-no-text                Skip images with no text (won't be saved).
--use-mtpe                    Turn on/off Machine Translation Post-Editing (MTPE) on the command line (currently Linux only)
--save-text                   Save extracted text and translations to a text file.
--load-text                   Load extracted text and translations from a text file.
--save-text-file SAVE_TEXT_FILE  Similar to --save-text, but with a specified file path. (default: '')
--prep-manual                 Prepare for manual typesetting by outputting blanked, inpainted images, and copies of the original image for reference
--save-quality SAVE_QUALITY   Quality of saved JPEG images, from 0 to 100 where 100 is best (default: 100)
--config-file CONFIG_FILE     Path to a configuration file (default: None)
WebSocket Mode Options
ws                  run in WebSocket mode
--host HOST         Host of the WebSocket service (default: 127.0.0.1)
--port PORT         Port of the WebSocket service (default: 5003)
--nonce NONCE       Nonce used to secure internal WebSocket communication
--ws-url WS_URL     Server URL for WebSocket mode (default: ws://localhost:5000)
--models-ttl MODELS_TTL  Time in seconds to keep models in memory after last use (0 means forever)
API Mode Options
shared              run in API mode
--host HOST         Host of the API service (default: 127.0.0.1)
--port PORT         Port of the API service (default: 5003)
--nonce NONCE       Nonce used to secure internal API server communication, set 

manga-image-translator (zyddnys/manga-image-translator)

Searching Database…

Что это такое?Переводчик текста на манге и любых изображениях «под ключ»: он находит текст, распознаёт его через OCR, переводит машинным переводом, стирает оригинальные надписи и вписывает перевод обратно в картинку.
Что именно происходит, когда он переводит страницу?Запускается конвейер из взаимозаменяемых моделей — детектор текста, OCR, переводчик, модель-инпейнтер, которая удаляет исходный текст, плюс опциональный колоризатор для чёрно-белых страниц.
Как его запустить?Основной способ — Docker: веб-сервер стартует на порту 8000 и сохраняет результаты в /result. Есть ещё пакетный режим из командной строки и режим API-сервиса (порт по умолчанию 5003).
Нужен ли API-ключ для переводчиков?Некоторым сервисам перевода нужны API-ключи — их передают в Docker-контейнер как переменные окружения; какие бэкенды их требуют, перечислено для каждого переводчика в настройках README.
Он справляется с любой страницей без проблем?Самое слабое место — детекция текста: мелкий или неровный размер шрифта может её сбить. В README советуют upscaleratio 2, настроенный detectionsize и maskdilationoffset 10-30 для лучшего покрытия маской.
Какой переводчик лучше всего работает с японского на английский?Для японского на английский README рекомендует Sugoi. Для японского на китайский там указаны sakura или переводчик на базе OpenAI, причём OpenaiTranslator умеет подгружать собственный файл глоссария, чтобы термины были единообразными.
Могу ли я подключить его к своим скриптам или приложениям?Да — помимо веб-интерфейса есть режим API и режим WebSocket, а документация OpenAPI доступна по адресу 127.0.0.1:8000/docs, так что изображения можно отправлять и получать результаты программно.
Есть ли официальный сайт, куда можно просто загружать картинки?В README есть ссылка на официальную демо-версию, которую поддерживает zyddnys, но в описании репозитория сказано, что старый адрес cotrans.touhou.ai уже не работает, так что надёжный способ — развернуть проект самому через Docker.
Как переводить картинки, которые лежат на моём компьютере, если я запускаю проект в Docker?Примонтируйте свою папку как volume в /app внутри контейнера, а затем в командах CLI используйте внутренние пути вида /app/... вместо путей на вашем компьютере.
Могу ли я управлять тем, как выглядит переведённый текст?Да — задайте шрифт, например fonts/animeace3.ttf, через --font-path, увеличьте fontsizeoffset, если текст получается слишком мелким, а --manga2eng впишет перевод во всю речевую облачко, а не в строку исходного текста.
Creator
zyddnys
Size
87.4 MB
Stars
10.5K
Age
5y
Commits · 90 Days