Sorts characters by pixel density.
Characters have different "visual weight" when rendered. This program measures the exact pixel density of each character in a given font and outputs them sorted from darkest to lightest (or vice versa).
pip install Pillow fonttools
# Table output (default: dense to sparse)
python3 densort.py -f "DejaVu Sans Mono" -i chars.txt
# C-style bitmap arrays (8x8 and 16x16)
python3 densort.py -f "Comic Sans MS" -i chars.txt -b
# Ascending order (sparse to dense)
python3 densort.py -f "Monaco" -i chars.txt -o asc
# Direct font path
python3 densort.py -f /path/to/font.ttf -i chars.txt
# Adjust font ratio for taller or wider characters (thai, arabic, etc)
python3 densort.py -f "Noto Sans Thai" -i chars.txt -b -r 0.8A text file containing characters to analyze, for example Paul Bourke's character ramp for grayscale:
$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,"^`'.
Table mode: Density values and Unicode codepoints for each character, and a ready-to-use density ramp string.
Bitmap mode: C-style arrays with 8x8 and 16x16 pixel representations of each character.
WTFPL