faure has asked for the wisdom of the Perl Monks concerning the following question:

At work 'a friend of mine' is writing a lot of little intranet CGI applications. His firm's graphics dept made up an intranet style guide, and they went out and comissioned a special mandatory font for the banner atop each page.

But they won't distribute the font! Instead of

<div class="mandatoryBannerFont">Application Title</div>
He has to make a .gif.

"But it is impossible to duplicate this font," they say. "So please order your custom .gif here."

And then they are charging him $170 per image, so there is a requisition form and manager sign-off and everything else. And lots of times what he really wants is some dynamic text up there...

However he recently noticed that the font files are sitting in AFS (-644) so the wisdom I seek (on his behalf) is:

Is there a perlish way to make images out of PS fonts?

(A .pl sitting with the font files is piping raw ps through Ghostscript and 4 bitmap filters before reading the other end of the pipe with GD. It's usable, but takes about 10 seconds... )

TIA-- :)

Replies are listed 'Best First'.
Re: Font Mafia
by Corion (Patriarch) on Aug 11, 2001 at 22:44 UTC

    My personal, ugly way of doing this would be the following approach :

    Render each glyph of the font (like, 'A'..'Z','a'..'z') into its own bitmap, and create your banners from that, either via a small CGI Perlscript (merlyn had a very interesting Apache page-not-found handler for creating nice rounded corners), or make a Perl script that combines these gif-glyphs on the fly into a large banner.

    Some more elaboration on merlyns approach, as seen in one of his Web Techniques columns :

    You create a directory, where your webserver can write files into, say, /banners. You set up a script as the "file-not-found" handler for that directory. All banner images are included as images like <IMG src="/banners/Text of banner.gif">, where "Text of banner" obviously means the text of the banner. Whenever such an image is not found, your script gets called as the error handler for that image. Your script then creates the file via the 10 seconds Perl/Ghostscript/GD program, returns it to the browser and also writes it to disk in the directory. This means, that after your first call, you get a cached version without having to worry about maintaining the correct banners in the directory.

    If you're worried about the /banners/ directory getting too large, set up a reaper job that simply wipes out all files in that directory - this only means that your banner cache will be flushed and the first person(s) to request the banner will have to wait a little bit longer.

      Thanks and ++ to everyone...

      Going to try piecing together a big gif from individual letter gifs with GD (if that is what you guys meant). Hopefully (?) faster than ghostscript and pbmplus...

      I loved merlyn's 404 cache trick by the way. (But alas I cannot touch the servers.)

Re: Font Mafia
by traveler (Parson) on Aug 12, 2001 at 02:39 UTC
    I am no PS guru, but maybe this can help get you started:

    I see that there is a PostScript::Font module for processing PS fonts. That should help with getting the metric info needed by PostScript::TextBlock. Or you could check out one of the other modules in Postscript-Font on cpan to see if one of them can fetch the font info from your font.

    Then I'd use something like pstoedit (which uses ghostscript) to convert the PS to a GIF or whatever format you need. I would not expect this to be lightening fast, though.

    HTH, --traveler

Re: Font Mafia
by HamNRye (Monk) on Aug 12, 2001 at 03:12 UTC

    Make GIF's out of each of the letters, (Use ATM for ps fonts, and just "text tool" them in PSP or Gimp.) And then a program like "fly" can combine them. Matt Wright's counter uses this technique.

    Also, if you really know PS, create an eps of the banner and convert. (eps2gif) This is what we use here for outputting our publishing banner. (same idea.)

    Hope it helps. ~Hammy

Re: Font Mafia
by Dr. Mu (Hermit) on Aug 12, 2001 at 21:07 UTC
    One problem with using separate gif glyphs created from the individual letters is that you then become responsible for kerning. This is the adjustment of letter pairs like "Te" that look best when slightly overlapped. The font metrics should give you the info needed to do this properly, but you won't be able just to tack letters next to each other and expect professional-looking results. I'd favor a more Postscript-centric approach, since Postscript handles the kerning details for you.