Back to Home 100% Free

Pic to XPM Converter

Convert PNG, JPG, and other formats to color X PixMap (XPM) C source headers offline.

Drag & Drop Your Images Here

Supports PNG, JPG, WEBP, GIF, BMP, SVG, TIFF (Max 20MB per file)

Transformation Settings

Width (px)
Height (px)

When transparency is enabled, transparent regions are preserved as "None" in XPM. Otherwise, they are filled with the chosen background color.

Understanding the XPM File Format Structure

The X PixMap (XPM) format is a text-based image format used primarily in the X Window System. It represents images as C source code, allowing them to be directly included in C/C++ applications. An XPM file format (XPM3) consists of a C header declaration containing an array of strings representing:

  • Dimensions & Metadata: A string detailing the image width, height, number of unique colors, and characters per pixel (cpp).
  • Color Table: Defines mapping from characters to specific color values, supporting RGB hex values, color names, or "None" for transparent pixels.
  • Pixel Data Matrix: A series of strings representing scanlines of the image, where each pixel is represented by characters mapping back to the color table.

How Characters-Per-Pixel Color Mapping Works

XPM maps color arrays to printable ASCII characters:

  • For images with few colors (up to 90), a single character per pixel (cpp = 1) is sufficient.
  • For higher color counts, the characters-per-pixel value scales dynamically to 2 or 3 characters per pixel, which allows representing thousands of unique colors.
  • This offline tool automatically calculates the optimal character-per-pixel layout, ensuring high fidelity color mapping without wasting space.

Handling Transparency in XPM

XPM has native support for transparent colors, conventionally designated as None in the color table. If "Preserve Transparency" is enabled, any pixel with an alpha value below 128 is treated as transparent and mapped to None. Alternatively, you can disable transparency to blend alpha channels with a solid background fill.

Actionable XPM Integration & Best Practices Checklist

1. Keep Aspect Ratio Locked for Resizing

When scaling images to include in source code headers, lock the aspect ratio to maintain the correct visual proportions.

2. Leverage Native Transparency

Toggle "Preserve Transparency" to output transparent backgrounds, making it simple to construct clean icons and UI elements.

3. C Variable Naming Standards

The C array identifier is derived from the input file's name. Special characters are replaced with underscores to maintain valid C syntax.

4. Secure Client-Side Execution

All data processing is performed directly on your local device. No images are uploaded to any external server.

XPM Specifications

MIME Type

image/x-xpixmap

Format Type

XPM3 (C source text header file format).

Color Palette

Supports monochrome, grayscale, and full RGB hex colors with native transparency (None).

Characters Per Pixel

Scales dynamically based on total unique colors (1, 2, or 3 characters per pixel).

Why XPM?

XPM is commonly used in X11 GUI toolkits, retro applications, and embedded firmware designs. Because it compiles directly as part of a C binary, XPM avoids file system loads for assets, serving as a reliable choice for standalone graphical components.

Frequently Asked Questions

What is an XPM image file?

XPM (X PixMap) is a text-based image format that stores pixel data in a C header syntax format. It was designed to store color pixmaps for the X Window System graphical user interface.

How does characters-per-pixel encoding scale?

The characters-per-pixel (cpp) setting increases depending on the number of unique colors in the image. Up to 90 colors use 1 character per pixel; up to 8,100 colors use 2 characters; and higher counts use 3 characters per pixel.

Does XPM support native transparency?

Yes, XPM explicitly supports transparency by defining a special keyword None in the color table. Transparent regions in input images are preserved as None when the transparency feature is enabled.

How does this tool process images offline?

Our offline converter uses the HTML5 Canvas API in your browser to inspect pixel components and generate XPM source text on-the-fly. No server uploads are required, making the tool secure and fast.

What variable identifier name is used in the C file?

The variable name is derived directly from the filename of your uploaded image. Non-alphanumeric characters are replaced with underscores to verify that it compiles as a valid C identifier.

Is the XPM converter free to use?

Yes, the converter is completely free with no usage limits. You can process single or multiple images locally without any restrictions.

Mascot assistant is ready!