Converting TTF Fonts to PNG

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
jpeni
Posts: 9
Joined: 2015-01-12T14:56:33-07:00
Authentication code: 6789
Location: Uniondale NY, USA

Converting TTF Fonts to PNG

Post by jpeni »

I have found that the following DOS batch file works well for converting Symbol TTF fonts to PNG files, but I also want to convert ALL symbols in the Symbol Font. I cant find a way to include the lower case ALPHABETIC and NON-ALPHABETIC and NUMERIC characters in the CONVERT process. Can someone suggest a way to include the lower case ALPHABETIC characters and the NON-ALPHABETIC and NUMERIC characters in the convert batch file.

@ECHO OFF
set f=wingding.TTF
set ps=200
set bg=white
set ext=png
set s=250x250
set alpha=A B C D E F G H I J K L M N O P Q R S T U V W Z Y Z
set num=0 1 2 3 4 5 6 7 8 9
For %%X in (%alpha% %num%) do (
convert -font %f% -pointsize %ps% -size %s% -background %bg% label:%%X %%X.%ext%)
pause
exit
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting TTF Fonts to PNG

Post by snibgo »

Digits and lower-case are as easy as upper-case. Punctuation is messy, with all the escapes needed by the two language processors (Window's cmd, and IM's command parser). It's easier to read the label from a text file, which needs no escapes at all.

If a text file called alphabet.txt contains ...

Code: Select all

 !"#$%&'()*+,-./0123456789:;<=>?
@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
`abcdefghijklmnopqrstuvwxyz{|}~
€‚ƒ„…†‡ˆ‰Š‹ŒŽ''""•–—˜™š›œžŸ
 ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß
àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
... then this command works:

Code: Select all

convert -font wingdings -pointsize 50 label:"@alphabet.txt" x.png
snibgo's IM pages: im.snibgo.com
jpeni
Posts: 9
Joined: 2015-01-12T14:56:33-07:00
Authentication code: 6789
Location: Uniondale NY, USA

Re: Converting TTF Fonts to PNG

Post by jpeni »

snibgo: Thanks. The alphabet.txt file works well for creating all symbols in ONE file.

Do you have any recommendations for converting all symbols in the TTF file to individual .PNG files?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting TTF Fonts to PNG

Post by snibgo »

Edit alphabet.txt, inserting a new line after every character. Suppose that file is named abc.txt. Use "for /F" to read every line of that file, and convert it. Don't use the character in the filename. Windows BAT syntax:

Code: Select all

set NUM=32

for /F %%C in (abc.txt) do (
  echo NUM=!NUM!
  %IM%convert -pointsize 20 label:%%C ch_!NUM!.png
  set /A NUM+=1
)
snibgo's IM pages: im.snibgo.com
jpeni
Posts: 9
Joined: 2015-01-12T14:56:33-07:00
Authentication code: 6789
Location: Uniondale NY, USA

Re: Converting TTF Fonts to PNG

Post by jpeni »

snibgo: It did NOT work for me. I even replaced the %IM% with the actual file location of ImageMagick and I entered -font webding.ttf after the convert command. It gracefully goes through the symbols and new line entries, but only generates one file named ch_!NUM!.png. One thing I did notice is that a file that contains NEW LINES after each symbol is changed to CARRIAGE RETURN after each symbol when saved as a .txt file.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting TTF Fonts to PNG

Post by snibgo »

You don't need %IM%.

Insert the line "setlocal enabledelayedexpansion" at the top.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting TTF Fonts to PNG

Post by snibgo »

The same ways as Latin text. My page http://im.snibgo.com/snutf8.htm shows some examples.
snibgo's IM pages: im.snibgo.com
Post Reply