What is the XPM file format?
An .xpm file stores a raster image in the X PixMap format - a plain-text, indexed-color format native to the X Window System. Unlike most image formats, an XPM file is also valid C source code: it declares a static string array that C and C++ programs can #include directly, without a separate image-loading step.
XPM3, the current and only widely used version, begins with the ASCII comment /* XPM */ at byte offset zero, followed by a C array definition. The first string in the array encodes the image dimensions, color count, and how many ASCII characters represent each pixel (1-4). Subsequent strings define a color table, mapping those character codes to X11 color names (such as cornflowerblue) or hex RGB values (#RRGGBB). Transparency is expressed by mapping a pixel code to the special name None - a mechanism that predates PNG alpha transparency by several years.
Because the format is pure ASCII, .xpm files can be version-controlled, diff'd, and generated programmatically without binary tools. File size grows linearly with pixel count, making the format impractical for photographs but well-suited for small icons and UI bitmaps.
XPM remains the native icon format for many X11 toolkits such as Motif and legacy GTK. Modern Linux desktops prefer SVG or PNG for icons, but X11 applications still commonly ship XPM fallbacks. GIMP, ImageMagick, XnView, and IrfanView all support the format on modern systems.
Security & safety
RISK: LOWXPM is a plain-text ASCII format; it cannot contain executable code or macros. Malformed XPM files could theoretically trigger bugs in parsing libraries (historical CVEs exist in libXpm on X11 systems), but modern patched versions are not vulnerable. Risk for everyday users is negligible.
Format details
in a nutshellPrograms that open XPM files
Technical details
deep spec| File encoding | Plain ASCII text (7-bit safe; also valid C source code) |
| File signature | /* XPM */ at byte offset 0 (XPM3); XPM2 files start with ! XPM2 |
| Color model | Indexed palette; 1-4 printable ASCII characters per pixel map to color entries |
| Color specification | X11 color names (e.g. cornflowerblue) or #RRGGBB hex values per palette entry |
| Transparency | None X11 color name maps a pixel code to full transparency (no separate alpha channel byte) |
| Compression | None - each pixel stored as 1-4 literal ASCII characters |
| Format versions | XPM1 (1989, monochrome C macros), XPM2 (1990, standalone data), XPM3 (1991, C syntax - current) |
| Maximum palette | Up to 65,536 simultaneous indexed colors |
| MIME type | image/x-xpixmap |
| Dimensions | No hard limit; file size grows linearly with pixel count (each pixel = chars_per_pixel ASCII bytes) |
| C integration | File content can be #included directly into C/C++ source and compiled without a loader |
| Released | 1989 (XPM1, Daniel Dardailler, Bull Research Center) |
| Latest version | XPM3 (1991), documented in XPM Manual v3.4i (September 1996, Arnaud Le Hors) |
| Open standard | Yes · royalty-free |
| Specification | www.xfree86.org |
XPM conversions
Community Q&A
asked by usersNo questions yet - be the first to ask about XPM files.