Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

img2c

A simple command-line tool to convert images into C bitmap arrays for embedded systems, microcontrollers, and display drivers.

Features

  • 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

Requirements

  • Pillow

Install dependencies:

pip install pillow

Usage

python img2c.py <input_image> <width> <height> [--format rgb565|rgb888] [--name ARRAY_NAME]

Arguments

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)

Examples

Basic conversion to RGB565 (most common for displays):

python img2c.py image.png 240 240

RGB888 for higher color fidelity:

python img2c.py photo.jpg 320 240 --format rgb888

Custom array name:

python img2c.py image.png 64 64 --name bitmap1

Output Format

The tool generates a .c file with a single C array containing packed pixel data:

const uint16_t image[57600] = {
    0xFFFF, 0x0000, 0xF800, 0x07E0, ...
};

Motivation

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.

Future Work

  • 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

About

A simple command-line tool to convert images into C bitmap arrays

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages