Rosenberger Image Replacement

I’ve been playing around with Stewart Rosenberger’s excellent Dynamic Text Replacement technique lately. It’s a simple and elegant technique, and it works beautifully well with TrueType fonts. It gets a little bit more tricky if you want to use PostScript fonts, though. On the ALA discussion, Stewart says that “you could change the PHP script to use PS fonts very easily”. Well….

  • It’s not as simple as replacing the ImageTTFBBox and ImageTTFText calls with their PostScript counterparts ImagePSBBox and ImagePSText. The PS versions take different parmeters in a different order, and they return a different results array. Read the documentation carefully.
  • …and you’ll need to explicitly load the PostScript font before using it, and dispose of it when you’re done.
  • …and once you’ve done all that work, you need to make sure that your web host has compiled PHP with support for Type 1 PostScript fonts, using the --with-t1lib option, because otherwise you’ll get nothing but errors when you try to deploy.

Nuts. Maybe I should have checked that last step first.

If you have access to a copy of Windows NT4 (how quaint!), you can convert a Type 1 font into a TrueType font by dragging it into the Windows\Fonts folder. (NT generates a .ttf font because it doesn’t have native PS support. Later versions of Windows do have native support, and so they don’t do the conversion when you install a PS font.) The quality of the generated TrueType font leaves a lot to be desired, however, and even aside from the licensing issues, I wouldn’t consider it as a source for Dynamic Text Replacement.

So what next? Well, I could rewrite Stewart’s script to use ImageMagick for generating the images. Alternatively, I could try Shaun Inman’s Flash Replacement technique. (I’d prefer to stick with images instead of Flash, though. The text isn’t selectable, and you end up with a bigger download, but images are faster to render, have fewer flickering issues, and fewer cross-browser/standards niggles.) Or I could splash out and buy a TrueType version of the font I want to use. Or…I could just use a font I already have in TrueType format. Such a wealth of choice!

I think I’ll be taking the easy, cheap option.

Update (Thu 8 Sept 2004)

Mike Davidson’s Scalable Inman Flash Replacement technique (sIFR) is looking like a glorious alternative.