---
name: "text2image"
section: "1"
platform: "linux"
package: "tesseract-ocr"
version: "5.5.0-1+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/text2image"
---

# text2image(1)

generate OCR training pages.

## NAME

text2image - generate OCR training pages.

## SYNOPSIS

**text2image** --text *FILE* --outputbase *PATH* --fonts\_dir *PATH* \[OPTION\]

## DESCRIPTION

[text2image(1)](/text2image/1.md) generates OCR training pages. Given a text file it outputs an image with a given font and degradation.

## OPTIONS

- *--text FILE*

  File name of text input to use for creating synthetic training data. (type:string default:)

- *--outputbase FILE*

  Basename for output image/box file (type:string default:)

- *--fontconfig\_tmpdir PATH*

  Overrides fontconfig default temporary dir (type:string default:/tmp)

- *--fonts\_dir PATH*

  If empty it use system default. Otherwise it overrides system default font location (type:string default:)

- *--font FONTNAME*

  Font description name to use (type:string default:Arial)

- *--writing\_mode MODE*

  Specify one of the following writing modes. *horizontal* : Render regular horizontal text. (default) *vertical* : Render vertical text. Glyph orientation is selected by Pango. *vertical-upright* : Render vertical text. Glyph orientation is set to be upright. (type:string default:horizontal)

- *--tlog\_level INT*

  Minimum logging level for tlog() output (type:int default:0)

- *--max\_pages INT*

  Maximum number of pages to output (0=unlimited) (type:int default:0)

- *--degrade\_image BOOL*

  Degrade rendered image with speckle noise, dilation/erosion and rotation (type:bool default:true)

- *--rotate\_image BOOL*

  Rotate the image in a random way. (type:bool default:true)

- *--strip\_unrenderable\_words BOOL*

  Remove unrenderable words from source text (type:bool default:true)

- *--ligatures BOOL*

  Rebuild and render ligatures (type:bool default:false)

- *--exposure INT*

  Exposure level in photocopier (type:int default:0)

- *--resolution INT*

  Pixels per inch (type:int default:300)

- *--xsize INT*

  Width of output image (type:int default:3600)

- *--ysize INT*

  Height of output image (type:int default:4800)

- *--margin INT*

  Margin round edges of image (type:int default:100)

- *--ptsize INT*

  Size of printed text (type:int default:12)

- *--leading INT*

  Inter-line space (in pixels) (type:int default:12)

- *--box\_padding INT*

  Padding around produced bounding boxes (type:int default:0)

- *--char\_spacing DOUBLE*

  Inter-character space in ems (type:double default:0)

- *--underline\_start\_prob DOUBLE*

  Fraction of words to underline (value in \[0,1\]) (type:double default:0)

- *--underline\_continuation\_prob DOUBLE*

  Fraction of words to underline (value in \[0,1\]) (type:double default:0)

- *--render\_ngrams BOOL*

  Put each space-separated entity from the input file into one bounding box. The ngrams in the input file will be randomly permuted before rendering (so that there is sufficient variety of characters on each line). (type:bool default:false)

- *--output\_word\_boxes BOOL*

  Output word bounding boxes instead of character boxes. This is used for Cube training, and implied by --render\_ngrams. (type:bool default:false)

- *--unicharset\_file FILE*

  File with characters in the unicharset. If --render\_ngrams is true and --unicharset\_file is specified, ngrams with characters that are not in unicharset will be omitted (type:string default:)

- *--bidirectional\_rotation BOOL*

  Rotate the generated characters both ways. (type:bool default:false)

- *--only\_extract\_font\_properties BOOL*

  Assumes that the input file contains a list of ngrams. Renders each ngram, extracts spacing properties and records them in output\_base/\[font\_name\].fontinfo file. (type:bool default:false)

## USE THESE FLAGS TO OUTPUT ZERO-PADDED, SQUARE INDIVIDUAL CHARACTER IMAGES

*--output\_individual\_glyph\_images BOOL*

If true also outputs individual character images (type:bool default:false)

*--glyph\_resized\_size INT*

Each glyph is square with this side length in pixels (type:int default:0)

*--glyph\_num\_border\_pixels\_to\_pad INT*

Final\_size=glyph\_resized\_size+2\*glyph\_num\_border\_pixels\_to\_pad (type:int default:0)

## USE THESE FLAGS TO FIND FONTS THAT CAN RENDER A GIVEN TEXT

*--find\_fonts BOOL*

Search for all fonts that can render the text (type:bool default:false)

*--render\_per\_font BOOL*

If find\_fonts==true, render each font to its own image. Image filenames are of the form output\_name.font\_name.tif (type:bool default:true)

*--min\_coverage DOUBLE*

If find\_fonts==true, the minimum coverage the font has of the characters in the text file to include it, between 0 and 1. (type:double default:1)

Example Usage: \`\`\` text2image --find\_fonts \\ --fonts\_dir /usr/share/fonts \\ --text ../langdata/hin/hin.training\_text \\ --min\_coverage .9 \\ --render\_per\_font \\ --outputbase ../langdata/hin/hin \\ \|& grep raw \| sed -e *s/ :.\*/" \\\\/g* \| sed -e *s/^/ "/* \>../langdata/hin/fontslist.txt \`\`\`

## SINGLE OPTIONS

- *--list\_available\_fonts BOOL*

  List available fonts and quit. (type:bool default:false)

## HISTORY

[text2image(1)](/text2image/1.md) was first made available for tesseract 3.03.

## RESOURCES

Main web site: **https://github.com/tesseract-ocr** Information on training tesseract LSTM: **https://tesseract-ocr.github.io/tessdoc/TrainingTesseract-4.00.html**

## SEE ALSO

[tesseract(1)](/tesseract/1.md)

## COPYING

Copyright (C) 2012 Google, Inc. Licensed under the Apache License, Version 2.0

## AUTHOR

The Tesseract OCR engine was written by Ray Smith and his research groups at Hewlett Packard (1985-1995) and Google (2006-2018).
