3 define('text2png_debug', true);
6 class WikiPlugin_text2png
9 var $name = 'text2png';
10 var $description = 'text2png';
12 function getDefaultArguments() {
14 return array('text' => "Hello WikiWorld!",
18 function run($dbi, $argstr, $request) {
19 extract($this->getArgs($argstr, $request));
20 return $this->text2png($text,$l);
23 function text2png($text,$l) {
25 //basic image creation and caching
26 //you MUST delete the image cache yourself if you change the drawing routines!
28 //uncomment debug string above to see whether image was saved to or loaded from cache
29 //and what the path is.
32 //http://download.php.net/manual/en/function.dcgettext.php
33 //dcgettext and dgettext aren't available functions on my system.?? -carsten
34 //this doesn't seem to work anyway, always get english. ??
38 //if (!$l == "C") {include("locale/$l/LC_MESSAGES/phpwiki.php");}
39 //$text = gettext($text);
40 //putenv("LANG=$oldlang");
42 $filename = $text . ".png";
44 if ($l == "C") { $l = "en"; } //FIXME: hack for english, C=en ??
45 $filepath = getcwd() . "/images/$l";
47 if (!file_exists($filepath ."/". $filename)) {
49 if (!file_exists($filepath)) {
51 mkdir($filepath, 0777); //permissions affected by user the www server is running as
55 // add trailing slash to save some keystrokes later
58 // prepare a new image
59 $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.");
62 $bg_color = ImageColorAllocate($im, 255, 255, 255);
63 $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
65 // http://download.php.net/manual/en/function.imagettftext.php
66 // array imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, string text)
69 $text_color = ImageColorAllocate($im, 175, 175, 175);
70 //shadow is 1 pixel down and 2 pixels right
71 ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text);
73 $text_color = ImageColorAllocate($im, 0, 0, 0);
74 ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text);
76 //maybe an alternate text drawing method in case ImageTTFText doesn't work
77 //ImageString($im, 2, 10, 40, $text, $text_color);
79 // to dump directly to browser:
80 //header("Content-type: image/png");
84 $success = ImagePng($im, $filepath . $filename);
91 // create an <img src= tag to show the image!
92 // this could use some better error reporting
95 if (defined('text2png_debug')) {
98 $html .= Element('p', "Image saved to cache file: " . $filepath . $filename) . "\n" ;
100 $html .= Element('p', "Image loaded from cache file: " . $filepath . $filename) . "\n" ;
103 $urlpath = DATA_PATH . "/images/$l/";
104 $html .= Element('img', array('src' => $urlpath . $filename, 'alt' => $text));
106 $html .= Element('p', "Error writing png file: " . $filepath . $filename) . "\n";
117 // c-hanging-comment-ender-p: nil
118 // indent-tabs-mode: nil