Glyph Maps Script - PHP

TOM-MLL's picture

Do any of you guys know how font sites are creating the glyph map images they post? It seems myfonts, font squirrel and font spring are all using the same similar code, any ideas? Example:

charmap.png19.35 KB
pica pusher's picture

It looks like they're using the GD library, if that wasn't glaringly obvious.

You could cut out the work of drawing the grid and glyph-name characters by creating your own image, opening it and drawing the glyph set onto it.

I believe GD lib works with .otf and .ttf and unicode, but check the documentation! If you need UTF-8 you may be out of luck.

Té Rowan's picture

FontForge can print text to an image, as can ImageMagick and GraphicsMagick. I think all of them use FreeType. Haven't checked if netpbm can. Have totally no idea of PHP's capabilities in that regard.

fontsquirrel's picture

It is all in PHP with the GD library as mentioned. Not as difficult as you might think.

TOM-MLL's picture

I assumed GD and php, imagemagick is very slow when working with type to image. My concern is how can you "query" the font per say, like opentype, and show all the glyphs. I was thinking some sort of for each loop of unicode values, but not sure.

fontsquirrel's picture

Showing Opentype glyphs is extremely difficult. Showing glyphs that have Unicode points, not so much. Just use FontForge to determine what glyphs are available in a font and then send that to your image script.

TOM-MLL's picture

Yeah, I haven't seen any GD code yet that works with Glyph ids, only unicode and char#s. Also, never thought of using fontforge with this, thought it might only confuse things, hehe.

Ankh's picture

You might want to investigate the "fontaine" program for diffing out which chracters to show...

TOM-MLL's picture

Ankh, wow! Thank you for that information on fontaine, I have never even head of that one!

TOM-MLL's picture

Been messing with fontforge on the box all night though, but using it via the command line is quite challenging, anyone know of any good documentation on this?

TOM-MLL's picture

BTW, fontaine is nice but seems it returns a bit too much info, and does not really return just a listing of the actual glyphs in the font.

Fontforge, I cannot get it to communicate with php via the command prompt, seems beter for a GUI environment like osx/windows.

Keep going in circles with freetype and php/gd, but I did stumble across the Open Font Library charmap open source script (, but cannot get it to output based on the idea above. So, after a few days of dead ends, I think its time to start early and go into a New Years Eve drinking binge... ;)

Té Rowan's picture

The FontForge docs (on Sourceforge) are more hacker-friendly than user-friendly, but if you dig and sift through the the files on scripting, you should find what you need. It's mainly on its native scripting language, but there are also some details on Python scripting.

fontsquirrel's picture

Wow, Fontaine looks great. Thanks for the info Ankh!

TOM-MLL's picture

After a little break, I revisited this. Using Fontaine worked quite nice, its the only thing I have seen so far that can read both TTF and OTF very clean. Once I got the JSON output filtered, you can pluck out the JSON values you would like, very nice. But, this hasn't helped me much on the character map idea, at this point I might go exploring some outside coders to finish it. Not sure how GD and PHP only can display this idea (as mentioned above). Maybe with truetype files, but I cannot see just those two alone being able to display opentype glyph tables. You guys at fontsquirrel must be pulling some crazy GD/PHP trickery.

fontsquirrel's picture

We have not yet implemented a display of OpenType glyphs. This is frankly impossible with the software as is without hacking the font itself.

Theunis de Jong's picture

... without hacking the font itself.

Do you mean, without setting valid Unicode points to each and every single glyph? I've written a small utility to output the character map of an OTF font into a text file, but it's of no use for glyphs. (JSON is not in my list of output options, but it could be added, were I inclined to.)

Using FreeType, it should be possible to write a C program to output an image alike the sample, but containing all glyphs, so it's probably possible with PHP as well.

See my SeeFont, for example; a thin Windows wrapper around FreeType, not limited to showing just Unicode characters.

TOM-MLL's picture

I think this is very interesting, considering opentype has been out for quite some time now, yet the GD/PHP setup still does not support it fully when we discuss things like above. Just look at the php calls, they all start with TTF, strange considering you now have so much moving into @font-face world, or maybe not so strange.

I hope someone picks up the ball and updates this in the near future. The idea of using fontforge to convert files to ttf, then read that out is nasty, nasty and more nasty...but then again, you gotta do what you gotta do? ;)

PabloImpallari's picture

Just checked again and is now showing the entire thing. Showing all OT glyphs, reordered.

TOM-MLL's picture

Small update. Still working away on this, seems to get php to read an otf file (even just extended latin chars) is not possible. But if the font is in ttf format, then it will display all the items (minus opentype extras). So, just getting say like the Euro symbol to show in php with the built in fucntions of imagettftext will not output via otf correctly, you would need to convert the otf to ttf first.

Still made no ground on getting the opentype features to show yet, such as salts and swash, etc.

But I think there is some misleading info about php/gd is all you need, sure. But I am not seeing php/gd even read the extended items of OTF files correctly, tried numerous ways to send the unicode values into php, no dice.

If anyone has done this (contradicting above), feel free to share.. ;)

TOM-MLL's picture

I felt I should update this again, not sure why, haha. But after months (I think i have actually spent a year on this, quite depressing) I have got this working (limited) by using TTX/Fonttools to export the font data to XML. The only issue now, is I still cannot get it to dump the opentype extras (eg: salt) into an charmap image, mainly because of the unicode missing issue.

Any ideas oh how to use say fontforge or something in conjunction here to apply unicode values onto the extra opentype options?

Syndicate content Syndicate content