LinuxCommandLibrary

ppmdraw

Draws images using PPM format data

TLDR

Draw on the specified PPM image by executing the supplied script

$ ppmdraw -script '[setpos 50 50; text_here "hello!"; ]' [path/to/image.pnm] > [path/to/output.pnm]
copy

Draw on the specified PPM image by executing the script in the specified file
$ ppmdraw -scriptfile [path/to/script] [path/to/image.pnm] > [path/to/output.pnm]
copy

SYNOPSIS

ppmdraw [-maxval maxval] [-width width] [-height height] [-color color] [-background color] [-textsize number] [-font font] drawing-commands [ppmfile]

PARAMETERS

-maxval maxval
    Sets the maximum color value for the output PPM image.

-width width
    Specifies the width of the output image if no input PPM is provided; otherwise, it is ignored.

-height height
    Specifies the height of the output image if no input PPM is provided; otherwise, it is ignored.

-color color
    Sets the initial or current drawing color. Colors can be specified by name, hexadecimal triplet, or RGB triplet.

-background color
    Sets the background color of the image if no input PPM is given and a new image is created.

-textsize number
    Sets the size of the font for the text drawing command.

-font font
    Specifies the font to be used for the text drawing command.

DESCRIPTION

The ppmdraw command, a part of the powerful Netpbm suite, is a versatile utility designed for drawing various geometric shapes directly onto Portable Pixmap (PPM) images. It can take an existing PPM image as input and modify it, or generate a new black PPM image if no input file is provided. Users define drawing operations through a sequence of commands, allowing for the creation of lines, circles, rectangles, ellipses, arcs, and filled shapes, alongside plotting individual pixels and rendering text. The output is always a modified PPM image. ppmdraw is exceptionally useful for programmatic image generation, adding overlays, or performing simple graphical modifications within scripts.

CAVEATS

Drawing commands are executed sequentially in the order they appear on the command line.
The coordinate system typically starts at (0,0) in the top-left corner.
Color specification can be flexible (names, hex, RGB) but requires correct syntax.

DRAWING COMMANDS SYNTAX

Beyond the command-line options, ppmdraw functions by interpreting a series of specific drawing commands provided as arguments. These commands define the shapes and operations to be performed on the image. They are parsed from left to right, and each command may have its own set of required arguments:

plot x y: Draws a single pixel at the specified coordinates.
line x1 y1 x2 y2: Draws a line from (x1,y1) to (x2,y2).
rectangle x1 y1 x2 y2: Draws a rectangle defined by two corner coordinates.
circle x y radius: Draws a circle centered at (x,y) with the given radius.
ellipse x y xradius yradius: Draws an ellipse centered at (x,y) with specified horizontal and vertical radii.
arc x y xradius yradius angle1 angle2: Draws an elliptical arc.
fill x y: Fills an enclosed area with the current drawing color, starting from (x,y) (flood fill).
color color_spec: Changes the current drawing color for subsequent commands.
text x y string: Draws the specified text string at (x,y) using the current font and size.

Many shape commands also have 'f' prefixes (e.g., frectangle) to draw filled versions of the shape.

HISTORY

ppmdraw is an integral part of the Netpbm project, a comprehensive suite of utilities for converting and manipulating graphic image files. Netpbm originated from pbmplus, developed by Jef Poskanzer, and has been a cornerstone of command-line image processing on Unix-like systems since the early 1990s. Its development reflects the long-standing need for scriptable and robust image manipulation tools.

SEE ALSO

pbm(5), pgm(5), ppm(5), pam(5), netpbm(1), ppmmake(1), ppmtext(1)

Copied to clipboard