Text to .bmp

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?".
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Text to .bmp

Post by dnorton »

I'm trying to produce a .bmp file with glyphs for the ascii characters 32 to 255. This needs to be for a specific font and pointsize. I have a file "characters.txt" containing the 224 characters. Using IM 6.9.1-9 on Windows 7 I've tried several variations along this line:

convert -font \windows\fonts\cour.ttf -pointsize 12 text:characters.txt courier12.bmp

This produces only two glyphs which resemble ascii 255 and 254. What am I doing wrong?

- Dan
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Text to .bmp

Post by Bonzo »

I would try something like:

Code: Select all

convert xc:white -font \windows\fonts\cour.ttf -pointsize 12 label:@characters.txt courier12.bmp
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

Bonzo wrote:I would try something like:

Code: Select all

convert xc:white -font \windows\fonts\cour.ttf -pointsize 12 label:@characters.txt courier12.bmp
Interesting... this produces two files:

courier12-0.bmp containing a white square
courier12-1.bmp containing the two glyphs for ascii 255 and 254
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Text to .bmp

Post by fmw42 »

I think it needs be -background white rather than xc:white. You also need a colon after label as label:@characters.txt

Code: Select all

convert -background white -font \windows\fonts\cour.ttf -pointsize 12 label:@characters.txt courier12.bmp
You might have to put quotes around @characters.txt, but try first without.
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

fmw42:

That produces:

courier12.bmp 23x15 with glyphs for ascii 255, 254, and blank

Quotes make no diff.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text to .bmp

Post by snibgo »

There may be something funny in your text file. With a file that contains ASCII 32 to 256, plus a new-line every 32 characters (file http://snibgo.com/imforums/ALPHABET.TXT ), I get:

Code: Select all

convert -font Courier-new -pointsize 20 label:@ALPHABET.TXT alphabet.png
Image
snibgo's IM pages: im.snibgo.com
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

snibgo:

In the following, "couriershort.txt" contains only the digits 0-9:

convert -font \windows\fonts\cour.ttf -pointsize 12 label:@couriershort.txt courier12.png

courier12.png is 23x15 and contains ascii 255, 254, and 48 = '0'

So, it must not be the input and .png seems to be the same as .bmp.
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Text to .bmp

Post by 246246 »

If you save text as UTF-8 everything should work fine.
I guess your text is UTF-16 LE or something like.
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

246246:

Yes! That's real progress. There seems to be something prepended but I can deal with that.

Thank you and everyone else who tried to help.

- Dan
246246
Posts: 190
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Text to .bmp

Post by 246246 »

dnorton wrote:There seems to be something prepended but I can deal with that.
It must be BOM. Try to save the text UTF-8 without BOM.
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

246246:

Tried successively removing characters at the front until I lopped off the blank (ascii 32) but the prepended thing stubbornly remains. My Form class>>fromBinaryStream: has firstByte = 66.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text to .bmp

Post by snibgo »

I'm not sure what you are trying to achieve. You say "ascii characters 32 to 255", but you are saving a file as UTF, not ASCII? And ASCII only goes up to 127.
snibgo's IM pages: im.snibgo.com
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

I'm building a strike font to include not only ascii 32 to 127 but also extended ascii 128 to 155. These are printable characters (maybe not all in courier) but in some other monospaced font. I need the glyphs for these characters. The technique will be applied to other fonts beside courier.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Text to .bmp

Post by snibgo »

Have you tried my command above, with ALPHABET.TXT that I linked to? What result do you get?
snibgo's IM pages: im.snibgo.com
dnorton
Posts: 8
Joined: 2015-07-23T12:56:02-07:00
Authentication code: 1151

Re: Text to .bmp

Post by dnorton »

Downloaded your ALPHABET.TXT, ran your convert and got the same thing that you show.

Took the new lines out, saved it from NotePad with encoding: UTF-8, ran your convert and got the same prepended string of characters as I discuss above.

Took the new lines out, saved it from NotePad with encoding: ANSI, ran your convert and got what appears to be the desired glyphs, that is *without* anything prepended. Now I'll try to make a strike font out of it.
Post Reply