CSS/PNG image replacement plugin (0.5)
zem_image_replace, or zem_ir, replaces text with a PNG image rendered using a TrueType font, and uses CSS to place the image on the page in such a way that the text is still accessible to text-only browsers. It’s similar, in some respects, to SIFR, except that zem_ir uses PNG and CSS where SIFR uses Flash and Javascript.
Because it integrates with Textpattern, zem_ir can be safely used to automatically turn any text into an image – not just a static heading, but article titles, dates, even excerpts and entire articles (not that we’d recommend that). All images are cached to save bandwidth and minimize server load. In most cases the title images created by zem_ir are very small, often less than 1kb each.
The image is generated by code based on Stewart Rosenberger’s Dynamic Text Replacement script. zem_ir supports several different CSS replacement methods, based on the most widely tested techniques. Alternative methods can be implemented using the class attribute.
Typical use might be something like this:
<txp:zem_ir font="myfont.ttf" wraptag="h2"><txp:page_title /></txp:zem_ir>
Which would automatically generate a PNG image containing the page title rendered in the specified font, and display it with code similar to this:
<h2 style="margin: 0 0 0 -5000px; background: url('/images/zir/b0f4c80ec436ee047716afc02b79cc92.png') no-repeat top right; height: 24px; text-align: left;">my page title</h2>
nb – this example assumes your image directory is writable, and the font file is stored in your home directory (not public_html).
A more complex example, using the new zem_ir_set tag to pre-define attributes:
<txp:zem_ir_set font="myfont.ttf" fontsize=32 backgroundcolor="#fff" color="#ccc" wraptag="h1" />
<txp:zem_ir_set group="subhead" font="myfont.ttf" fontsize=16 wraptag="h2" />
<txp:zem_ir><txp:page_title /></txp:zem_ir>
<txp:zem_ir group="subhead"><txp:site_slogan /></txp:zem_ir>
<txp:zem_ir><txp:title /></txp:zem_ir>
The first <txp:zem_ir_set> tag defines the default parameters used by <txp:zem_ir>. The second one defines a second set of defaults, identified by group="subhead". The page title and article title are displayed using the default settings (fontsize=32, etc); the site slogan is displayed using the group="subhead" settings (fontsize=16, etc). (Default parameters, where no group is specified, are not inherited by other groups, so the site slogan will not use the color and backgroundcolor settings specified in the first <txp:zem_ir_set /> tag).
Tags
<txp:zem_ir_set /> – specify the default parameters used by <txp:zem_ir> tags. The group attribute may be used to create multiple independent groups of parameters.
<txp:zem_ir>...</txp:zem_ir> – create a PNG image containing the enclosed content, and use CSS to display it. The content may include any Textpattern tags, such as <txp:title />. Any parameters specified by zem_ir_set with the same group setting will be applied. Additional parameters may also be specified as attributes to the zem_ir tag.
For compatibility with older versions, <txp:zem_image_replace> is an alias for <txp:zem_ir>.
Attributes
Both tags support the following attributes:
zem_ir will use any parameters specified by a zem_ir_set tag with the same group name. If no group is specified, both tags use a group named ‘default’./home/myname/).tr="_/" will convert underscores and slashes to spaces. Default is no conversion.tr. Default is " ", a space.<txp:zem_ir text="hello world" /> is equivalent to <txp:zem_ir>hello world</txp:zem_ir>.Some notes on the different CSS replacement methods:
<span> tag.<img> tag with a link to the generated PNG image. Text content will be included in the alt attribute.zem_ir is Copyright 2004-2005 Threshold State.
Distributed under the terms of the GNU General Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
28 November 2004, 10:40 by Alex ·
Commenting is closed for this article.
How can I prevent/reduce the huge whitespace after the image-replaced text?
— Steve Jan 24, 02:36 am #
— John Oxton Apr 4, 02:56 pm #
I seem to get an error no matter where I put my font. For example, I’ve tried putting it under the files-directory and using font=”files/myfont.ttf”, but it still doesn’t work..
(why not public_html btw?)
— Brutal Apr 26, 02:36 am #