A simple command-line tool to convert images into C bitmap arrays for embedded systems, microcontrollers, and display drivers.
- Convert images to RGB565 (16-bit) or RGB888 (24-bit) C arrays
- Auto-resize images to your target resolution
- Outputs compact C source files ready for embedding
- Pillow
Install dependencies:
pip install pillowpython img2c.py <input_image> <width> <height> [--format rgb565|rgb888] [--name ARRAY_NAME]| Argument | Description |
|---|---|
input_image |
Path to input image file (PNG, JPG, BMP, etc.) |
width |
Target width in pixels (positive integer) |
height |
Target height in pixels (positive integer) |
--format |
Pixel format: rgb565 (default) or rgb888 |
--name |
Optional C array name (defaults to image stem) |
Basic conversion to RGB565 (most common for displays):
python img2c.py image.png 240 240RGB888 for higher color fidelity:
python img2c.py photo.jpg 320 240 --format rgb888Custom array name:
python img2c.py image.png 64 64 --name bitmap1The tool generates a .c file with a single C array containing packed pixel data:
const uint16_t image[57600] = {
0xFFFF, 0x0000, 0xF800, 0x07E0, ...
};This tool was created out of necessity. We found existing image-to-C converters lacking in several ways:
- Many are web-based only, requiring you to upload local images to external servers
- Others demand heavy dependencies or full build environments that clutter embedded development workflows
- Some simply don't run on certain systems
- Many only process one image at a time, making batch conversion painfully slow
img2c.py takes a simpler approach. It's a single Python script with just one dependency, runs locally offline, and outputs plain C arrays ready for any compiler or platform. Minimal overhead, maximum portability.
- Add monochrome mode for OLED and e-paper displays
- Add batch mode to process directories of images at once
- Add cropping option to extract regions before resizing
- Add rotation and flipping options to match display orientation
- Add thumbnail preview generation alongside main array
- Add PlatformIO/Arduino build integration for embedded projects
- Add VS Code extension for inline preview and conversion