3 define('text2png_debug', true);
6 class WikiPlugin_text2png
9 var $name = 'text2png';
11 function getDefaultArguments() {
13 return array('text' => "Hello WikiWorld!",
17 function run($dbi, $argstr, $request) {
18 extract($this->getArgs($argstr, $request));
19 return $this->text2png($text,$l);
22 function text2png($text,$l) {
24 //basic image creation and caching
25 //you MUST delete the image cache yourself if you change the drawing routines!
27 //to show debug string, whether image was saved or loaded from cache
28 //and what the path is
30 $filename = $text . ".png";
31 if ($l == "C") { $l = "en"; } //FIXME: hack for english, C=en
32 $filepath = getcwd() . "/images/$l";
34 if (!file_exists($filepath ."/". $filename)) {
36 if (!file_exists($filepath)) {
38 mkdir($filepath, 0777); //permissions affected by user the www server is running as
42 // add trailing slash to save some keystrokes later
45 // prepare a new image
46 $im = @ImageCreate(150, 50) or die ("Cannot Initialize new GD image stream. PHP must be compiled with support for GD 1.6 or later to create png files.");
49 $bg_color = ImageColorAllocate($im, 255, 255, 255);
50 $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
52 // http://download.php.net/manual/en/function.imagettftext.php
53 // array imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, string text)
56 $text_color = ImageColorAllocate($im, 175, 175, 175);
57 //shadow is 1 pixel down and 2 pixels right
58 ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text);
60 $text_color = ImageColorAllocate($im, 0, 0, 0);
61 ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text);
62 //ImageString($im, 2, 10, 40, $text, $text_color);
64 // to dump directly to browser:
65 //header("Content-type: image/png");
69 $success = ImagePng($im, $filepath . $filename);
76 // create an <img src= tag to show the image!
77 // this could use some better error reporting
80 if (defined('text2png_debug')) {
83 $html .= Element('p', "Image saved to cache file: " . $filepath . $filename) . "\n" ;
85 $html .= Element('p', "Image loaded from cache file: " . $filepath . $filename) . "\n" ;
88 $urlpath = DATA_PATH . "/images/$l/";
89 $html .= Element('img', array('src' => $urlpath . $filename, 'alt' => $text));
91 $html .= Element('p', "Error writing png file: " . $filepath . $filename) . "\n";
102 // c-hanging-comment-ender-p: nil
103 // indent-tabs-mode: nil