=====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. The text rendering script is from [[http://www.stewartspeak.com/dtr/ | 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) %% 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) $value) { // Was a preset provided? - Remember they are case-sensitive! if ($param == 'preset') {$preset=$this->htmlspecialchars_ent($vars['preset']);} if ($preset == 'H1') {include 'fontpresets/h1.php';} elseif ($preset == '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 == 'font') {$font=$this->htmlspecialchars_ent($vars['font']);} if ($param == 'size') {$size=$this->htmlspecialchars_ent($vars['size']);} if ($param == 'color') {$color=$this->htmlspecialchars_ent($vars['color']);} if ($param == 'background') {$background=$this->htmlspecialchars_ent($vars['background']);} if ($param == 'class') {$class=$this->htmlspecialchars_ent($vars['class']);} // Get the text... if ($param == 'text') {$text=$this->htmlspecialchars_ent($vars['text']);} } } // Get the image... $output = "\"".$text."\""; $output = $this->ReturnSafeHTML($output); print($output); ?>%% The rendering script: %%(php)[]{}-+_-=' ; $box = @ImageTTFBBox($size,0,$font,$test_chars) ; return $box[3] ; } /* attempt to create an image containing the error message given. if this works, the image is sent to the browser. if not, an error is logged, and passed back to the browser as a 500 code instead. */ function fatal_error($message) { // send an image if(function_exists('ImageCreate')) { $width = ImageFontWidth(5) * strlen($message) + 10 ; $height = ImageFontHeight(5) + 10 ; if($image = ImageCreate($width,$height)) { $background = ImageColorAllocate($image,255,255,255) ; $text_color = ImageColorAllocate($image,0,0,0) ; ImageString($image,5,5,5,$message,$text_color) ; header('Content-type: image/png') ; ImagePNG($image) ; ImageDestroy($image) ; exit ; } } // send 500 code header("HTTP/1.0 500 Internal Server Error") ; print($message) ; exit ; } /* decode an HTML hex-code into an array of R,G, and B values. accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff */ function hex_to_rgb($hex) { // remove '#' if(substr($hex,0,1) == '#') $hex = substr($hex,1) ; // expand short form ('fff') color if(strlen($hex) == 3) { $hex = substr($hex,0,1) . substr($hex,0,1) . substr($hex,1,1) . substr($hex,1,1) . substr($hex,2,1) . substr($hex,2,1) ; } if(strlen($hex) != 6) fatal_error('Error: Invalid color "'.$hex.'"') ; // convert $rgb['red'] = hexdec(substr($hex,0,2)) ; $rgb['green'] = hexdec(substr($hex,2,2)) ; $rgb['blue'] = hexdec(substr($hex,4,2)) ; return $rgb ; } /* convert embedded, javascript unicode characters into embedded HTML entities. (e.g. '%u2018' => '‘'). returns the converted string. */ function javascript_to_html($text) { $matches = null ; preg_match_all('/%u([0-9A-F]{4})/i',$text,$matches) ; if(!empty($matches)) for($i=0;$i %% ---- CategoryUserContributions