You are not logged in.
As the title points out, I'm trying to create an image from unicode text via command line. I tried...
convert -pointsize 48 -size 400 caption:测试用 text.png
But that results in question marks for the Chinese characters. So searching around online I discovered that I needed to specify a font which could display the characters. The characters show up just fine in Firefox, KDE, Kate, Terminal, etc so I know I have a font which can render them. I thought it might be DejaVu but this also resulted in question marks...
convert -font /usr/share/fonts/TTF/DejaVuSerif.ttf -pointsize 48 -size 400 caption:测试用 text.png
Any ideas?
Last edited by tony5429 (2011-01-31 23:17:41)
Offline
Definitely a font issue; try using some of these fonts.
Offline
Those first two characters seem very rare even in fonts that have fairly wide UTF8 coverage.
However, the following worked for me:
convert -font /usr/share/fonts/truetype/bitstream-cyberbit/Cyberbit.ttf -pointsize 48 -size 400 caption:测试用 text.png
Using the ttf-bitstream-cyberbit package from AUR.
I'm sure there are others that support these characters, maybe among those foutrelis linked to.
Offline
Thanks for the tips. However, I know I must already have a font which will do the trick as the characters show perfectly in Kate and Konsole. According to Kate and Konsole, I'm using the font "Monospace" which I understand refers to KDE's default monospace font. Does anyone know how I can figure out what KDE is using for its monospace font? In the KDE appearance settings the "fixed width" font is set to "monospace" too...
Offline
...Does anyone know how I can figure out what KDE is using for its monospace font?
From Konsole:
$ fc-match Monospace
Offline
Thanks, but then why does this still yield question marks?
[karam@boris ~]$ fc-match Monospace
DejaVuSansMono.ttf: "DejaVu Sans Mono" "Book"
[karam@boris ~]$ convert -font /usr/share/fonts/TTF/DejaVuSansMono.ttf -pointsize 48 -size 400 caption:测试用 text.png
Last edited by tony5429 (2011-01-27 12:34:09)
Offline
No ideas?
(maybe everyone's as stumped as I am...)
Offline
I'm not sure why the problem exists. My xterm displays the characters as boxes but gtk apps display them correctly. DejaVu Sans Mono is my xterm font.
Offline
Weird. Well for me the characters show up perfectly everywhere except in the images created by imagemagick....
Offline
My problem with xterm is probably that I never set up double-wide characters correctly. I really don't have much use for it. Xterm does recognize the glyphs as double-wide; it prints a box, then a space, then another box and another space...
Have you tried experimenting with locale or the LANG variable?
Offline
My locale is set to en_GB.UTF8. What is the LANG variable?
Interestingly if I use the font gkai00mp.ttf, which I found referenced here, the image comes out fine (no question marks). So it seems the issue must lie with how ImageMagick communicates with my DejaVu font....
Last edited by tony5429 (2011-01-28 04:30:10)
Offline
meh, imagemagick is degrading
i just tried with wthc06.ttf (HanWangGB06 font) and it almost sort of works
i used your command above and i followed the directions on their site
my opinion, imagemagick is broken and you need to find a different tool
edit: nvm, if i use the ukai font it works quite well (as far as i can tell)
Last edited by fsckd (2011-01-28 04:49:51)
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
I don't get why it would work with some fonts, but not DejaVu when every other app using DejaVu can render those characters...
Do you know of any other command-line tools which could do it?
Offline
GraphicsMagick gives boxes for characters. ImageMagick gives question marks.
Offline
Weird... Is there such a thing as a command-line web browser engine that I could invoke to read the text and pipe the output to an image? Something like...
webbrowserengine -input "<html><p>测试用</p></html>" -output image.png
Last edited by tony5429 (2011-01-28 19:06:15)
Offline
DejaVu doesn't contain those Chinese glyphs at all, so please don't blame ImageMagick for not rendering them.
So, Firefox, Kate, Terminal and the others you stated to use DejaVu, if encounter these characters, fall back to some other fonts to render them. These fonts are, however, not vector, but bitmap fonts. (This can be seen if you increase text size (Ctrl++ in Firefox): the Chinese characters don't change, they remain of their inherent size.)
Actually, e.g. /usr/share/fonts/misc/18x18ko.pcf.gz definitely contains the three example characters, so the mentioned apps may use this font as fall back.
Apparently ImageMagick doesn't handle bitmap fonts (I'm not sure), so you won't be able to hit your original target. Anyway, since you tried to parse "-pointsize 48", you wouldn't be satisfied with the font size.
Your only choice seems to be using the above mentioned CJK-approved TTFs.
EDIT: typo
Last edited by barto (2011-01-28 21:52:33)
“First principle, Clarice. Simplicity” – Dr. Hannibal Lecter
Offline
DejaVu doesn't contain those Chinese glyphs at all, so please don't blame ImageMagick for not rendering them. :)
Yeah, I made a bad call. :o
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
Ah! Well, this ImageMagick call is actually going into an application I'm writing. Basically I just need to be able to take any unicode text and create an image from it. So does anyone know how the font-fallback system (which Firefox, Kate, Konsole, etc are using) works so I can replicate it in my application by asking ImageMagick to use different fonts for different characters depending on varied character support? Or maybe the "Monospace" font already does that by searching through the fonts for a way to represent each character? And if that's the case then I just need to find a way to get ImageMagick to rely on "Monospace"...
Offline
Still unable to answer your exact question, but…
GNU Unifont has a practically full UTF8 coverage. Originally also a bitmap font, but its TTF port definitely does the trick with ImageMagick (pointsize 16).
“First principle, Clarice. Simplicity” – Dr. Hannibal Lecter
Offline
I'm sorry I didn't check DejaVu for those glyphs. That slipped by me completely.
To find good candidate fonts, try this:
$ fc-list :lang=zh
Droid Sans Fallback:style=Regular
AR PL UKai TW MBE:style=Book
AR PL UKai CN:style=Book
AR PL UKai HK:style=Book
AR PL UKai TW:style=Book
$ fc-list :lang=ja
Droid Sans Fallback:style=Regular
Droid Sans Japanese:style=Regular
IPAGothic,IPAゴシック:style=Regular
IPAPGothic,IPA Pゴシック:style=Regular
IPAMincho,IPA明朝:style=Regular
IPAPMincho,IPA P明朝:style=Regular
To find the fonts imagemagick knows about:
$ identify -list font | less
Last edited by thisoldman (2011-01-29 00:41:41)
Offline
Thanks all! I ended up using the TTF version of GNU Unifont - http://aur.archlinux.org/packages.php?ID=33588
Offline