Creating a font preview

2019-08-12 05:29发布

问题:

I am working on a site with a type designer. He doesn't want his fonts on font resellers and would like people to buy his own font on his site. He would like a web app that shows the live font and would also allow people to type in a input box to generate there own words with the font. Just like myfonts and other font websites have. How can I do this? JavaScript/jQuery if possible, or PHP.

回答1:

If the designer doesn't want people to be able to download the font without payment, JavaScript and CSS fonts wouldn't work as the font is sent to the client.

With PHP it's easy and possible, for example, to use the imagettftext function to render text in a font on the server, then send the rendered image as a reply to a HTTP request. imagettftext uses the GD and FreeType libraries, and should work without any extra setup on most PHP installations.



回答2:

You have a couple of options...

  • Prerender each character and just do a simple character to font glyph mapping.
  • Use an image library such as GD to render the text with the correct font.


回答3:

You can use sIFR library to use custom fonts on your webpage. It uses JS and Flash.

You can create in the beginning sample text and with JS connect it to some textarea to live update sFIR object.