Revision [16699]
This is an old revision of FontActionInfo made by WvhJe6 on 2007-05-31 10:37:54.
Rendering text with a font on the server
Example render
(Arcadia Light Standard 50pt black-on-white with transparency)
http://img.photobucket.com/albums/v257/karto/fonttest.png
This action takes text and renders it with a font on the server.(Arcadia Light Standard 50pt black-on-white with transparency)
http://img.photobucket.com/albums/v257/karto/fonttest.png
The text rendering script is from A List Apart/Stewart Rosenberger - I just did some crude hacks to make it work as an action (my PHP skills are extremely limited).
There appears to be a bug with Opentype fonts not rendering special characters properly, but I don't know if the problem is with the script, GD or freetype.
Truetype isn't affected, so I suspect freetype is to blame.
An entry would look like
{{font text="Text" font="TimesNewRoman" size="24" color="000000" background="ffffff"}}
The rendering script has variables for:
- Fontfile (needs to be on server of course)
- Font size (in points)
- Font color
- Background color
- Transparency (Note that it defaults to off now - that can be a problem on very thin fonts)
- Caching
The action supports classes and predefined styles.
<?php
//H1
$font = 'InsigniaLTStd.otf';
$size = '24';
$color = 'CC0000';
$background = 'FFFFFF';
$class = 'underline';
?>
//H1
$font = 'InsigniaLTStd.otf';
$size = '24';
$color = 'CC0000';
$background = 'FFFFFF';
$class = 'underline';
?>
It passes the image text as both the alt and title tags - I believe this will satisfy accesibility requirements.
It can render .ttf (Truetype) and .otf (Opentype) font files.
On an offnote - this is the first time I have done any PHP scripting, so if there are better ways of doing this, please let me know (it took me 2 hours figuring out how to pass stuff between the scripts :D ).
TODO:
- Testing...
- Hook it into WikiEdit to get custom fontmenus (is that at all possible/plausible?) Added presets instead
The action - save as /actions/font.php
%%(php)<?php
Get defaults
include ('fontpresets/default.php');
Where is the font rendering script?
$renderscript = "/actions/fontpresets/fontrenderer.php";
if (is_array($vars))
{
foreach ($vars as $param => $value)
{
Was a preset provided? - Remember they are case-sensitive!
if ($preset
'H1') {include 'fontpresets/h1.php';}
elseif ($preset 'H2') {include 'fontpresets/h2.php';}
'H2') {include 'fontpresets/h2.php';}
Uncomment/copy below line to add presets
elseif ($preset
'H3') {include 'fontpresets/h3.php';}
Was any overrides provided?
if ($param
'size') {$size=$this->htmlspecialchars_ent($vars['size']);}
if ($param
'background') {$background=$this->htmlspecialchars_ent($vars['background']);}
Get the text...
if ($param
'text') {$text=$this->htmlspecialchars_ent($vars['text']);}
}
}Get the image...
$output = "<img class=".$class." src=\"".$renderscript."?text=".$text."