定制 hcharbonnier/mangatranslation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hcharbonnier/mangatranslation

Composer 安装命令:

composer require hcharbonnier/mangatranslation

包简介

PHP manga automatic translator (Works with Google Cloud Platform)

README 文档

README

PHP manga automatic translator library (Works with Google Cloud Platform)

CPU Only, no cuda, no opencv, no local machine learning

Warning

  • I am not a dev, this project work well, but the code quality is probably shi...
  • In order to get acceptable result, your manga/comic raw quality has to be near perfect!!
  • Google translate work well when translated from chinese(manhua), but not so well from Japanese(Manga)

Frontend

If you want to test the library you can use the following example.php file or use the dedicated frontend : https://github.com/hcharbonnier/mangatranslation-frontend

Translation examples

Source

Source

Translated

Translated

Workflow summary

  • Open image (jpeg, png, gif or bmp)
  • Detect textboxes
  • Detect font size
  • OCR Text in textboxes
  • Remove old text from textboxes
  • Check in sqliteDB if we already know the translation for the current string
  • Use Google API to translate (or free Deepl API)
  • Expand textboxes if possible
  • Adapt translation font size to fit in textboxes
  • write translation in the corresponding textboxes
  • export image

Known Issues

  • Let me know

Installation

create a composer.json file in your project, and add:

{
    "minimum-stability": "dev",
    "require": {
         "hcharbonnier/mangatranslation": ">=1.3.0"
    }
}

then install depedencies:

composer install
mkdir uploads

Requirement

Dev additionnal requirements

  • php-7.4-xml
  • php-7.4-xmlrpc
  • php-7.4-mbstring

Example

example.php

<?php
require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload

use hcharbonnier\mangatranslation\MangaImage;

$trans=new MangaImage($argv[1]);
$trans->detect_block();
$trans->merge_near_block();
$trans->ocr();
$trans->translate("google");  // possible values are "google" (default) or "deepl" 
$trans->remove_empty_block();
$trans->clean_raw();
$trans->write_translation();
$trans->export($argv[2],90);

Then run:

$ export GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_GOOGLE_PROJECT.json
$ php example.php image.jpg translated.jpg

Extra features

Mangatranslation can be integrated with a custom frontend to perform better translation. This functions allow user to interact with the process:

Get list of textbox

$trans->get_blocks() : array

Manually specify additional a textbox

$trans->add_block($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4) : void

Get translation of textbox $id_block

$trans->get_block_translation(int $id_block) : string

Get OCR of textbox $id_block

$trans->get_block_ocr(int $id_block) : string

Manually specify translation

//to be call BEFORE translate() !!!
$trans->set_block_translation(int $id_block,"Translated text") : void

Manually specify cleaned raw image

$trans->set_cleaned_raw("toto_clean.jpg") : void

统计信息

  • 总下载量: 43
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2020-03-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固