LinuxCommandLibrary

ppmtoacad

Convert PPM image to AutoCAD DXF format

TLDR

Convert a PPM image to an AutoCAD slide

$ ppmtoacad [path/to/file.ppm] > [path/to/file.acad]
copy

Convert a PPM image to an AutoCAD binary database import file
$ ppmtoacad [[-d|-dxb]] [path/to/file.ppm] > [path/to/file.dxb]
copy

Restrict the colors in the output to 8 RGB shades
$ ppmtoacad -8 [path/to/file.ppm] > [path/to/file.dxb]
copy

SYNOPSIS

ppmtoacad [-color dxf_color_number] [-background dxf_color_number] [-dxftype {SOLID|TRACE}] [-scale scale_factor] [-blocksize pixels] [-layer layername] [ppmfile]

PARAMETERS

ppmfile
    The input Portable Pixmap (PPM) file to convert. If omitted, ppmtoacad reads from standard input.

-color dxf_color_number
    Specifies the AutoCAD color number to use for each pixel in the output DXF. If not specified, the default DXF color (usually 0) is used.

-background dxf_color_number
    Sets the AutoCAD color number for the background pixels. If this option is not provided, background pixels are simply ignored (not drawn).

-dxftype {SOLID|TRACE}
    Determines the type of DXF entity used to represent each pixel. The default is SOLID, which creates filled rectangles. TRACE can also be used, which creates filled polygons.

-scale scale_factor
    Applies a scaling factor to the output DXF image. For example, -scale 2.0 would make the output twice as large.

-blocksize pixels
    Specifies the size of square blocks of pixels to combine into a single DXF entity. This can reduce the output file size and complexity but may result in a loss of detail. For example, -blocksize 2 would treat every 2x2 pixel area as one unit.

-layer layername
    Assigns all generated DXF entities to a specified AutoCAD layer. The default layer is '0'.

DESCRIPTION

The ppmtoacad command is a utility from the Netpbm image manipulation toolkit. It converts a Portable Pixmap (PPM) image file into an AutoCAD DXF (Drawing Exchange Format) file. Each pixel in the input PPM image is typically represented as a distinct graphical entity, specifically an AutoCAD SOLID entity, in the output DXF file. This makes it useful for translating simple raster graphics, such as logos, floor plans, or pixel art, into a vector format suitable for CAD applications.

The command reads the PPM image from a specified file or from standard input if no file is given. It then generates the corresponding DXF code on standard output. By default, it converts pixels into solid, filled rectangles with a default color. Options allow for specifying background colors, scaling the output, combining blocks of pixels, and choosing different DXF entity types for representation. It's important to note that while it provides a basic raster-to-vector conversion, it's not a sophisticated vectorization tool and is best suited for images where each pixel's exact representation as a geometric primitive is desired.

CAVEATS

The output DXF file can become extremely large and complex for high-resolution PPM images, as each pixel is typically converted into a separate DXF entity. This command is best suited for images with relatively low resolution or simple graphical content, rather than photographic images. The resulting DXF is a basic pixel-level representation and lacks advanced vectorization features like curve fitting or intelligent object recognition.

OUTPUT STRUCTURE

By default, ppmtoacad represents each pixel from the input PPM as an AutoCAD SOLID entity. A SOLID entity in DXF is a filled quadrilateral defined by four points. When converting, each pixel's color (or a specified -color) determines the color of its corresponding SOLID entity, and its position in the image determines the entity's coordinates within the DXF drawing space.

HISTORY

ppmtoacad is part of the Netpbm project, a long-standing open-source suite of graphics programs primarily used on Unix-like operating systems. Netpbm originated from the Pbmplus package developed by Jef Poskanzer in the late 1980s. Its philosophy centers around simple, pipe-friendly tools that operate on basic image formats (PPM, PGM, PBM). ppmtoacad was developed to bridge the gap between simple pixel-based images and the widely used CAD environment, allowing for basic integration of raster data into DXF drawings.

SEE ALSO

ppm(5), pnm(5), netpbm(1), ppmtogif(1), ppmtopng(1)

Copied to clipboard