Skip to content

Instantly share code, notes, and snippets.

@VanessaE
Created January 11, 2017 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VanessaE/ed19e445245ffd582c7d64c27171bb19 to your computer and use it in GitHub Desktop.
Save VanessaE/ed19e445245ffd582c7d64c27171bb19 to your computer and use it in GitHub Desktop.
signs_lib char gen
#!/bin/bash
# Simple font generator for homedecor signs mod
# By Vanessa Ezekowitz
#
# License: WTFPL
# Usage:
#
# signs-chargen.sh fontname fontheight [top-excess bottom-excess left-excess right-excess]
#
# font is the standard X11 font spec, in quotes, such as:
# "-*-helvetica-*-r-*-*-12-*-*-*-*-*-*-*"
#
# Note that top+bottom excess can easily exceed the specified font size. The excess values
# must all be specified if any are.
textfont=$1
fontheight=$2
texcess=$3
bexcess=$4
lexcess=$5
rexcess=$6
pagesize="-size \"$((fontheight*2))x$((fontheight*4))\" xc:none"
cmdbase="convert $pagesize -font \"$textfont\" -gravity North -pointsize $fontheight "
trimargs1="+repage -gravity West -background red -splice 1x0 -background green -splice 1x0 -trim +repage -chop 1x0"
trimargs2="+repage -gravity East -background red -splice 1x0 -background green -splice 1x0 -trim +repage -chop 1x0"
choptopbottom="-gravity North -chop 0x"$texcess" -gravity South -chop 0x"$bexcess
chopsides="-gravity West -chop "$lexcess"x0 -gravity East -chop "$rexcess"x0"
# numbers require a slightly different command:
for charcode in `seq 48 57`; do
char=$(printf \\$(printf "%o" $charcode))
hexcode=$(echo -n "$char" |xxd -ps)
command=$cmdbase" -annotate 0 \"$char\" hdf_"$hexcode".png"
echo "$char : $hexcode"
eval $command
done
# then the rest of the ascii set, except there are a few we have to skip
for charcode in 32 `seq 35 47` `seq 58 91` 93 94 95 `seq 97 126`; do
char=$(printf \\$(printf "%o" $charcode))
hexcode=$(echo -n "$char" |xxd -ps)
command="$cmdbase -draw \"text 0,0 $char\" hdf_"$hexcode".png"
echo "$char : $hexcode"
eval "$command"
done
# those special cases are ! " * \ `
command="$cmdbase -annotate 0 \! hdf_21.png"
echo "! : 21"
eval $command
command="$cmdbase -annotate 0 \\\" hdf_22.png"
echo "\" : 22"
eval $command
command="$cmdbase -annotate 0 \* hdf_2a.png"
echo "* : 2a"
eval $command
command="$cmdbase -annotate 0 \\\\\\\\ hdf_5c.png"
echo "\\ : 5c"
eval $command
command="$cmdbase -annotate 0 \\\` hdf_60.png"
echo "\` : 60"
eval $command
if [ -z "$trimargs1" ] ; then
for i in `ls *.png`; do
mogrify +repage $choptopbottom $chopsides $i
done
else
for i in `ls *.png`; do
convert $i $trimargs1 XXXXX$i
mv XXXXX$i $i
convert $i $trimargs2 XXXXX$i
mv XXXXX$i $i
convert $i $choptopbottom $chopsides XXXXX$i
mv XXXXX$i $i
done
fi
convert -size $(((fontheight/2)+1))x$((fontheight*4)) xc:none $choptopbottom $chopsides hdf_20.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment