Skip to content

Instantly share code, notes, and snippets.

@weigert
Created February 5, 2023 12:43
Show Gist options
  • Save weigert/9f5c75381b51b27768ab9df2ee2a53c4 to your computer and use it in GitHub Desktop.
Save weigert/9f5c75381b51b27768ab9df2ee2a53c4 to your computer and use it in GitHub Desktop.
Convert Font to ASCII PNG Image / Texture
# font2asciipng.sh
#
# This script uses imagemagick to generate a simple .png
# texture with ascii characters [32-127] from a font.
#
# Author: Nicholas McDonald
# Parameters
FONTNAME="gohufont.otb"
GLYPH_W=8
GLYPH_H=14
OUTPUT="output.png"
TEX_W=$((96*$GLYPH_W))
# Compute the ASCII String
for i in {32..127}
do
ASCII="$ASCII$(printf "\\$(printf %o $i)")"
done
# Generate .PNG
echo $ASCII |\
convert -pointsize ${GLYPH_H} -font ${FONTNAME} -page ${TEX_W}x${GLYPH_H}+${GLYPH_W}+0 \
text: ${OUTPUT}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment