A Go tool that converts binary files (images, fonts, etc.) into C++ hex byte arrays for embedding directly into your C++ code.
- Convert any binary file to C++ hex array format
- Automatic variable naming based on filename
- Configurable bytes per line for readable output
- Support for multiple input files
- Output to file or stdout
- Preserves file size information
- Make sure you have Go installed (version 1.21 or later)
- Clone or download this project
- Build the executable:
go build -o hexify main.go# Convert a single file (auto-creates image.h)
hexify image.png
# Convert with .cpp extension (creates image.cpp)
hexify -ext cpp image.png
# Convert multiple files (creates image.h, font.h, icon.h)
hexify image.png font.ttf icon.ico
# Save output to custom file
hexify -o resources.h image.png
# Output to stdout instead of file
hexify -stdout image.png
# Specify custom variable name
hexify -var my_custom_image image.png-o <file>: Output file (default: auto-generated .h file)-var <name>: Variable name for the hex array (default: auto-generated)-bytes <n>: Number of bytes per line (default: 16)-ext <ext>: Output file extension (h or cpp, default: h)-stdout: Output to stdout instead of file-h: Show help
hexify logo.pngOutput (saved to logo.h):
// Auto-generated from: logo.png
// File size: 1234 bytes
const unsigned char logo_png_hex[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x08, 0x06, 0x00, 0x00, 0x00, 0x73, 0x7a, 0x7a,
// ... more bytes ...
};
const unsigned int logo_png_hex_size = 1234;hexify -ext cpp logo.pngCreates logo.cpp with the same content.
hexify -o resources.h -var my_logo -bytes 8 logo.pnghexify image.png font.ttf icon.icoCreates image.h, font.h, and icon.h files.
This tool is perfect for:
- Game Development: Embed textures, sounds, and fonts directly into your game executable
- Embedded Systems: Include configuration files, firmware updates, or resources
- Standalone Applications: Bundle resources without external file dependencies
- Cross-platform Development: Ensure resources are always available regardless of file system
After converting your files, you can use them in your C++ code like this:
#include "resources.h"
// Use the embedded image
void displayLogo() {
// logo_png_hex contains the PNG file data
// logo_png_hex_size contains the file size
displayImage(logo_png_hex, logo_png_hex_size);
}
// Use the embedded font
void loadFont() {
loadFontFromMemory(font_ttf_hex, font_ttf_hex_size);
}This tool works with any binary file:
- Images: PNG, JPG, GIF, BMP, ICO, etc.
- Fonts: TTF, OTF, etc.
- Audio: MP3, WAV, OGG, etc.
- Documents: PDF, DOC, etc.
- Any other binary file format
# Windows
go build -o hexify.exe main.go
# Linux
GOOS=linux go build -o hexify main.go
# macOS
GOOS=darwin go build -o hexify main.goThis project is open source and available under the MIT License.