Skip to content

AmpedWasTaken/Hexify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hexify

A Go tool that converts binary files (images, fonts, etc.) into C++ hex byte arrays for embedding directly into your C++ code.

Features

  • 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

Installation

  1. Make sure you have Go installed (version 1.21 or later)
  2. Clone or download this project
  3. Build the executable:
go build -o hexify main.go

Usage

Basic Usage

# 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

Command Line Options

  • -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

Examples

Convert an image file (auto-creates logo.h):

hexify logo.png

Output (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;

Convert with .cpp extension:

hexify -ext cpp logo.png

Creates logo.cpp with the same content.

Convert with custom settings:

hexify -o resources.h -var my_logo -bytes 8 logo.png

Convert multiple files (creates separate files):

hexify image.png font.ttf icon.ico

Creates image.h, font.h, and icon.h files.

Use Cases

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

C++ Usage Example

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);
}

Supported File Types

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

Building for Different Platforms

# 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.go

License

This project is open source and available under the MIT License.

About

Converts binary files to C++ hex byte arrays

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published