You are not logged in.

#1 2011-01-26 23:28:32

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#2 2011-01-26 23:40:53

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

Definitely a font issue; try using some of these fonts.

Offline

#3 2011-01-27 03:11:11

frabjous
Member
Registered: 2010-07-13
Posts: 367

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#4 2011-01-27 03:22:24

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#5 2011-01-27 10:18:01

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

tony5429 wrote:

...Does anyone know how I can figure out what KDE is using for its monospace font?

From Konsole:

$ fc-match Monospace

Offline

#6 2011-01-27 12:33:35

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#7 2011-01-27 18:48:00

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

No ideas?

(maybe everyone's as stumped as I am...)

Offline

#8 2011-01-27 23:23:26

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#9 2011-01-28 02:48:10

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

Weird. Well for me the characters show up perfectly everywhere except in the images created by imagemagick....

Offline

#10 2011-01-28 03:25:20

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#11 2011-01-28 04:28:08

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#12 2011-01-28 04:31:27

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#13 2011-01-28 06:11:53

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#14 2011-01-28 11:04:37

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

GraphicsMagick gives boxes for characters.  ImageMagick gives question marks.

Offline

#15 2011-01-28 18:29:01

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#16 2011-01-28 19:08:01

barto
Member
From: Budapest, Hungary
Registered: 2009-10-22
Posts: 88

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

DejaVu doesn't contain those Chinese glyphs at all, so please don't blame ImageMagick for not rendering them. smile

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. smile

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

#17 2011-01-28 20:53:50

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

barto wrote:

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

#18 2011-01-28 21:42:51

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#19 2011-01-28 22:50:48

barto
Member
From: Budapest, Hungary
Registered: 2009-10-22
Posts: 88

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#20 2011-01-29 00:41:00

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

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

#21 2011-01-31 23:13:20

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to Create an Image from UTF8 Text via Command-line

Thanks all! I ended up using the TTF version of GNU Unifont - http://aur.archlinux.org/packages.php?ID=33588

Offline

Board footer

Powered by FluxBB