PHP code example of hcharbonnier / mangatranslation

1. Go to this page and download the library: Download hcharbonnier/mangatranslation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hcharbonnier / mangatranslation example snippets



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


$trans->get_blocks() : array

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

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

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

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

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

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