2 rcs_id('$Id: text2png.php,v 1.8 2002-01-09 18:06:49 carstenklapp Exp $');
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
33 * You MUST delete the image cache yourself in /images if you
34 * change the drawing routines!
37 $filename = $text . ".png";
40 * FIXME: need something more elegant, and a way to gettext a
41 * different language depending on any individual
42 * user's locale preferences.
45 if ($l == "C") { $l = "en"; } //english=C
46 $filepath = getcwd() . "/images/$l";
48 if (!file_exists($filepath ."/". $filename)) {
50 if (!file_exists($filepath)) {
52 // permissions affected by user the www server is running as
53 mkdir($filepath, 0777);
57 // add trailing slash to save some keystrokes later
63 * FIXME: needs a dynamic image size depending on text
64 * width and height $im = @ImageCreate(150, 50);
68 $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.");
69 // FIXME: Error manager does not transform URLs passed
71 $error_text .= QElement('a',
72 array('href' => "http://www.php.net/manual/en/function.imagecreate.php",
75 trigger_error( $error_text, E_USER_NOTICE );
78 $bg_color = ImageColorAllocate($im, 255, 255, 255);
79 $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
81 /* http://download.php.net/manual/en/function.imagettftext.php
82 * array imagettftext (int im, int size, int angle, int x, int y,
83 * int col, string fontfile, string text)
87 $text_color = ImageColorAllocate($im, 175, 175, 175);
88 // shadow is 1 pixel down and 2 pixels right
89 ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text);
92 $text_color = ImageColorAllocate($im, 0, 0, 0);
93 ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text);
96 * An alternate text drawing method in case ImageTTFText
99 //ImageString($im, 2, 10, 40, $text, $text_color);
101 // To dump directly to browser:
102 //header("Content-type: image/png");
106 $success = ImagePng($im, $filepath . $filename);
113 // create an <img src= tag to show the image!
116 if (defined('text2png_debug')) {
119 trigger_error(sprintf(_("Image saved to cache file: %s"),
120 $filepath . $filename),
123 trigger_error(sprintf(_("Image loaded from cache file: %s"),
124 $filepath . $filename),
128 $urlpath = DATA_PATH . "/images/$l/";
129 $html .= Element('img', array('src' => $urlpath . $filename,
132 trigger_error(sprintf(_("couldn't open file '%s' for writing"),
133 $filepath . $filename), E_USER_NOTICE);
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil