LinuxCommandLibrary

texttoppm

Convert text to PPM image

SYNOPSIS

texttoppm [options] [text_file]

PARAMETERS

-font fontfile
    Specifies the TrueType font file (.ttf) to use for rendering the text.

-fontsize size
    Sets the font size in pixels for the text.

-width width
    Defines the desired width of the output image in pixels.

-height height
    Defines the desired height of the output image in pixels.

-leftmargin margin
    Sets the left margin in pixels for the text within the image.

-rightmargin margin
    Sets the right margin in pixels for the text within the image.

-topmargin margin
    Sets the top margin in pixels for the text within the image.

-bottommargin margin
    Sets the bottom margin in pixels for the text within the image.

-lineheight height
    Sets a custom line height in pixels, overriding default font metrics.

-pad lines
    Adds lines number of blank lines at the top of the text.

-text textfile
    Reads text input from the specified textfile instead of standard input.

-foreground color
    Sets the color of the text. Can be a color name (e.g., 'red') or a hex RGB value (e.g., '#FF0000').

-background color
    Sets the background color of the image. Accepts color names or hex RGB values.

-halign left|center|right
    Specifies horizontal alignment of the text within the image.

-valign top|center|bottom
    Specifies vertical alignment of the text within the image.

-characters characters
    Limits the rendering to a specific set of characters provided as a string.

-encoding encoding
    Specifies the character encoding of the input text (e.g., 'UTF-8', 'ISO-8859-1').

-header
    Includes a header line at the top of the output image, typically showing the command used.

-plain
    Suppresses the inclusion of any header line in the output image.

-alpha
    Generates an alpha mask (PGM) alongside the main PPM image, useful for transparency when combined with other tools.

-verbose
    Enables verbose output, printing progress and debugging messages to stderr.

DESCRIPTION

The texttoppm command is part of the Netpbm suite of graphics utilities. It converts plain ASCII text into a Portable Pixmap (PPM) image. This tool is invaluable for embedding textual information directly into image files, creating graphical banners from text, or simply visualizing text content in an image format. Users can control various aspects of the rendered text, including the font family (TrueType fonts), font size, foreground and background colors, margins, line height, and text alignment. It reads text from standard input or a specified file and outputs the resulting PPM image to standard output, making it highly compatible with other Netpbm tools for further image manipulation or conversion to formats like JPEG or PNG.

CAVEATS

Requires TrueType fonts (.ttf) for font rendering. Output is strictly in PPM format, meaning it will require further Netpbm utilities like pnmtojpeg or pnmtopng for conversion to more common image formats like JPEG or PNG. This command does not natively support complex text layouts such as bidirectional text, advanced ligatures, or highly specific typographic features.

INPUT AND OUTPUT

By default, texttoppm reads text from standard input (stdin). This means you can pipe text directly from other commands or redirect it from a file. To specify an input file directly, use the -text option. The resulting image is written to standard output (stdout) as a PPM (Portable Pixmap) file. This output can be redirected to a file (e.g., > output.ppm) or, more commonly, piped to another Netpbm utility for further processing or conversion to other image formats.

COMMON USAGE PATTERN

A typical usage involves piping text into the command and then piping its PPM output to another Netpbm tool for conversion to a more widely viewable format. For example:
echo "Hello World" | texttoppm -font /usr/share/fonts/truetype/dejavu/DejaVuSans.ttf -fontsize 24 -foreground '#FF0000' -background '#0000FF' | pnmtopng > hello.png
This command chain creates a PNG image named 'hello.png' containing the text 'Hello World' rendered in red color on a blue background, using a specified TrueType font.

HISTORY

texttoppm is an integral part of the Netpbm project, a long-standing and widely used open-source toolkit for graphic file manipulation. Netpbm's development began in the late 1980s and has evolved to include hundreds of tools for converting, modifying, and creating various image formats, with PPM being one of its core formats. texttoppm specifically was developed to bridge the gap between simple text and image data, maintaining the project's philosophy of simple, composable tools.

SEE ALSO

netpbm(1), pnm(5), pnmtojpeg(1), pnmtopng(1), ppm(5)

Copied to clipboard