LinuxCommandLibrary

pnmtoxwd

Convert PNM image format to X Window Dump

TLDR

Convert a PNM image file to XWD

$ pnmtoxwd [path/to/input_file.pnm] > [path/to/output_file.xwd]
copy

Produce the output in the DirectColor format
$ pnmtoxwd [[-d|-directcolor]] [path/to/input_file.pnm] > [path/to/output_file.xwd]
copy

Set the color depth of the output to b bits
$ pnmtoxwd [[-ps|-pseudodepth]] [b] [path/to/input_file.pnm] > [path/to/output_file.xwd]
copy

SYNOPSIS

pnmtoxwd [-outfile name] [-verbose] [-map|-nomap] [-depth N] [-rgb|-norgb] [-invert|-noinvert] [-frame|-noframedata] [pnmfile]

PARAMETERS

-outfile
    Specifies the name of the output XWD file. If omitted, the output is written to standard output.

-verbose
    Enables verbose mode, printing informational messages about the conversion process to standard error.

-map
    Forces the output to be a pseudo-color (mapped) XWD file if the input PNM image has 256 colors or fewer. This is often the default behavior when appropriate.

-nomap
    Forces the output to be a TrueColor XWD file, even if a pseudo-color representation could be used. This ensures 24-bit or 32-bit output.

-depth
    Sets the desired bit depth of the output XWD file. Common values include 1, 8, 16, 24, or 32. The program will attempt to match colors to the specified depth.

-rgb
    When generating a TrueColor XWD, uses an RGB colormap rather than a standard X colormap. This can be beneficial for certain image viewers.

-norgb
    Disables the use of an RGB colormap for TrueColor XWD output. This is typically the default behavior.

-invert
    Inverts the colors of the image during conversion (e.g., black becomes white, white becomes black).

-noinvert
    Disables color inversion, maintaining the original color scheme. This is the default setting.

-frame
    Includes fake XWD frame data in the output file. This can be useful for applications that expect specific frame information from a true X window dump, though the data itself is not real.

-noframedata
    Excludes fake XWD frame data from the output file. This is the default setting.

DESCRIPTION

pnmtoxwd is a Netpbm utility designed to convert images from the Portable Anymap (PNM) format into the X Window Dump (XWD) format. PNM encompasses Portable Bitmap (PBM), Portable Graymap (PGM), and Portable Pixmap (PPM), allowing pnmtoxwd to process monochrome, grayscale, and color images.

The XWD format is commonly used to store screenshots or 'dumps' of windows and screens from the X Window System. This command is invaluable for developers and users who need to interchange image data between Netpbm's flexible image manipulation tools and applications that specifically require XWD input, such as certain X-based image viewers or development tools.

pnmtoxwd intelligently handles various aspects of the conversion, including color depth management, mapping of colors (for pseudo-color XWDs), and TrueColor output, ensuring compatibility with a broad range of X displays and applications. It typically reads the PNM image from standard input if no file is specified, and writes the resulting XWD image to standard output, making it suitable for use in shell pipelines.

CAVEATS

The XWD format has specific requirements for color depths and colormaps; while pnmtoxwd attempts to be robust, compatibility issues with some specific X applications may arise, especially when using non-standard depths or colormap types.
The -frame option adds dummy XWD frame data, not actual window geometry or properties, which might not satisfy all XWD parsers expecting real window information.

INPUT/OUTPUT BEHAVIOR

By default, pnmtoxwd reads image data from standard input (stdin) and writes the converted XWD image to standard output (stdout). This design facilitates its use within shell pipelines, allowing it to be easily chained with other Netpbm utilities or commands. The -outfile option can be used to direct output to a specified file instead.

COLOR HANDLING LOGIC

pnmtoxwd intelligently manages color conversion. For input images with 256 or fewer colors, it attempts to produce a pseudo-color (mapped) XWD, which is more compact. For images with more colors or when forced by options like -nomap, it generates a TrueColor XWD (typically 24-bit or 32-bit), accurately representing a broader color spectrum. The -depth option provides fine-grained control over the output bit depth, allowing users to optimize for specific display requirements.

HISTORY

pnmtoxwd is a part of the Netpbm project, a comprehensive suite of graphics file format converters and manipulators. Netpbm itself has a long history, originating from the pbmplus package created by Jef Poskanzer in the late 1980s. pnmtoxwd, like other Netpbm tools, benefits from this heritage of robust, pipeline-friendly design, evolving over time to support various XWD features and Netpbm's internal image handling improvements.

SEE ALSO

xwdtopnm(1), pnm(5), xwd(1), netpbm(1)

Copied to clipboard