I'm trying to create many single-character images using convert
. The purpose is to provide a plastics specialist with images to print onto keyboard keycaps.
The ImageMagick documentation suggests something like this:
printf "\u2318" | convert -size 100x100 label:@- -font unifont-Medium command.png
or
echo ⌘ | convert -size 100x100 label:@- -font unifont-Medium command.png
or
convert -size 100x100 label:'⌘' -font unifont-Medium command.png
which is supposed to print the place of interest symbol, but it instead produces a question mark.
I have confirmed (using charmap
) that the unifont-Medium
fontset actually includes this glyph. I know that other fonts on my system can also provide this glyph, because I could see it before installing unifont, but I've not been able to work out what their name is.
I also tried using LaTeX (e.g. TexLive with all the extras and the utf8x
package) but none of the special characters are supported.
There are a lot of forum questions about printing chinese characters with imagemagick and other special characters… the following does work for me:
convert -background lightblue -fill blue -pointsize 32 \
label:' é è à ù ç Ö ÿ ‘ ’ “ ” ° ² ³ € x ÷ ' label_i8n.gif
but it just doesn't work for the UTF-8 characters that are actually important to me.
How can I convert arbitrary unicode characters to images?
UPDATE: I gave up, looks like a bug. Instead, I created a bunch of scripts to generate and render SVG, open sourced here: kinesis-dvorak
Best Answer
I tried the same commands and got the same results.
Changing to the unicode for the letter G works fine though:
I would post this question to the ImageMagick Discourse site to see why this is occurring. I can assist if you're unsure how to do this or proceed.
Debugging convert
You can add the
-debug annotate
switch to see whatconvert
's up to.Example
UPDATE #1 - Debugging further
This issue was irking me so I think I've finally figured it out. The issue is the selection of the font, and it not being able to display that particular glyph.
First off you can use this command to see which fonts you have available within
convert
. So let's start there.The above shows a sample, every font has lines similar to the above. Incidentally, running this command shows we have several hundred fonts:
Next we're going to go through the task of encoding our character,
\u2318
using every font we have. This sounds complicated but is fairly trivial with some well thought out one liners via Bash.This snippet will use a for loop to run through each font, running a modified version of your
convert
command.Now we look through the results. Many of the fonts could not display this particular glyph but several could, which would seem to indicate that it's not necessarily a bug in ImageMagick, but rather a limitation of the fonts themselves. Here's a list of the fonts that I had that could display this glyph.
I visually went through the entire ~260 resulting
.gif
files to determine which worked and which didn't. Here's a sample of a few of the ones that worked just so you can see them.References