Generating shadowed/outlined glyphs with a font
Posted: 2011-01-25T01:39:29-07:00
I'm generating "font textures" for a game, which are images containing rendered characters and a text files describing the rectangles of each character in the image. The game requires a plain font, and a shadowed and outlined font. To be able to get the size of each character, I'm generating an image for each character, and montaging them into the textures. The following are the commands I'm using:
The outline and shadow characters are not aligned correctly since I'm just trimming their images, while the plain font does not have this problem. Would generating the outline and shadow images using label: instead of -annotate be a good solution? How can I do it without writing multiple images for each character?
Code: Select all
# Plain character
convert -background transparent -fill '#f5f5f5' label:'c' c.png
# Outlined character
convert -size 300x300 xc:transparent \
-fill '#550b0b' -annotate +51+49 'c' \
-annotate +49+51 'c' \
-annotate +51+51 'c' \
-annotate +49+49 'c' \
-fill '#e9f9f9' -annotate +50+50 'c' \
-trim c-outlined.png
# Shadowed character
convert -size 300x300 xc:transparent \
-font 'font' -pointsize 12 \
-fill '#000000' -annotate +50+51 'c' \
-fill '#ffffff' -annotate +50+50 'c' \
-trim c.shadowed.png
# Montage into texture
montage -label '' -background transparent -gravity SouthWest \
-geometry '1x1+0+0<' ?.png texture.png