Useful little commandline tool for embedded applications. Converts an image from PNG, JPG, TGA, BMP, GIF or flattened PSD to C arrays. Uses STB for image parsing, no other dependencies. Arrays are currently always exported in Little Endian order.
Usage: img2array [options] image [ > dest.h ]
-a STRING array alignment prefix
(default: "")
-e STRING array alignment suffix
(default: "__attribute__ ((aligned (4)))")
-n STRING array base name
(default: image filename w/o ext)
-m INT destination color mode (default 0):
0 = argb8888
1 = rgb888
2 = rgb565
3 = argb4444
$ img2array -m 3 -n logo48 logo.png
#pragma once
#include <stdint.h>
const uint8_t logo48_argb4444[4608] __attribute__ ((aligned (4))) = {
0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0,
...
};
git clone git@github.com:thi-ng/img2array.git
cd img2array
make
If you want to reduce the tool’s filesize (default: ~256KB) and limit
image format support, uncomment some of the #define
’s in main.c
.
This project is open source and licensed under the Apache Software License 2.0.