Text to image with Chinese characters

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
djd
Posts: 41
Joined: 2011-11-12T22:20:18-07:00
Authentication code: 8675308

Text to image with Chinese characters

Post by djd »

The following script appears to work OK with normal text

# Convert text in a text file to an image
#
# text2image.ksh Name.txt
#
# Produces: Nametext.png


N=$(basename $1 .txt)
M="$N""Text"
imgconvert -size 1000x1000 xc:white -font "SimSun" -pointsize 56 \
-fill black -annotate +15+80 "@$N.txt" \
"$M".png

However with Chinese font, such as SimSun in the script as above, a `?' mark is inserted
in front of the first line.
eg if a text file contains the Chinese character for `I' 我 (Pinyin wo3) and is saved
as utf8, then the image produced has a question mark`?' in front of the 我 character.
Subsequent lines in the file are OK.

Various Chinese fonts were tried and the result was the same.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text to image with Chinese characters

Post by snibgo »

I guess your text file has been saved in UTF-8 with a Byte Order Mark (BOM) at the start. The cure is to strip the BOM before passing to IM.
snibgo's IM pages: im.snibgo.com
Post Reply