4 * File loading and saving diagnostic messages, to see whether an
5 * image was saved to or loaded from the cache and what the path is
7 define('text2png_debug', true);
10 class WikiPlugin_text2png
17 function getDefaultArguments() {
19 return array('text' => "Hello WikiWorld!",
23 function run($dbi, $argstr, $request) {
24 extract($this->getArgs($argstr, $request));
25 return $this->text2png($text,$l);
28 function text2png($text,$l) {
31 * Basic image creation and caching
32 * You MUST delete the image cache yourself in /images if you change the
36 $filename = $text . ".png";
38 /* FIXME: need something more elegant, and a way to gettext a different
39 * language depending on any individual user's locale preferences.
41 if ($l == "C") { $l = "en"; } //english=C
42 $filepath = getcwd() . "/images/$l";
44 if (!file_exists($filepath ."/". $filename)) {
46 if (!file_exists($filepath)) {
48 // permissions affected by user the www server is running as
49 mkdir($filepath, 0777);
53 // add trailing slash to save some keystrokes later
56 /* prepare a new image
57 * FIXME: needs a dynamic image size depending on text width and height
58 * $im = @ImageCreate(150, 50);
61 $error_text = _("Unable to create a new GD image stream. PHP must be compiled with support for the GD library version 1.6 or later to create PNG image files.");
62 // FIXME: Error manager does not transform URLs passed through it.
63 $error_text .= QElement('a', array('href' => "http://www.php.net/manual/en/function.imagecreate.php",
64 'class' => 'rawurl'), "PHP web page");
65 trigger_error( $error_text, E_USER_NOTICE );
68 $bg_color = ImageColorAllocate($im, 255, 255, 255);
69 $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
71 /* http://download.php.net/manual/en/function.imagettftext.php
72 * array imagettftext (int im, int size, int angle, int x, int y, int col,
73 * string fontfile, string text)
77 $text_color = ImageColorAllocate($im, 175, 175, 175);
78 // shadow is 1 pixel down and 2 pixels right
79 ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text);
82 $text_color = ImageColorAllocate($im, 0, 0, 0);
83 ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text);
85 /* An alternate text drawing method in case ImageTTFText
88 #ImageString($im, 2, 10, 40, $text, $text_color);
90 // To dump directly to browser:
91 #header("Content-type: image/png");
95 $success = ImagePng($im, $filepath . $filename);
102 // create an <img src= tag to show the image!
105 if (defined('text2png_debug')) {
108 trigger_error(sprintf(_("Image saved to cache file: %s"),
109 $filepath . $filename), E_USER_NOTICE);
111 trigger_error(sprintf(_("Image loaded from cache file: %s"),
112 $filepath . $filename), E_USER_NOTICE);
115 $urlpath = DATA_PATH . "/images/$l/";
116 $html .= Element('img', array('src' => $urlpath . $filename, 'alt' => $text));
118 trigger_error(sprintf(_("couldn't open file '%s' for writing"),
119 $filepath . $filename), E_USER_NOTICE);
130 // c-hanging-comment-ender-p: nil
131 // indent-tabs-mode: nil