4 * Copyright (C) 2002 Johannes Große
6 * This file is part of PhpWiki.
8 * PhpWiki is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * PhpWiki is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 // +---------------------------------------------------------------------+
25 // +---------------------------------------------------------------------+
26 // | simple test of the WikiPluginCached class which provides a |
27 // | text to image conversion. |
28 // | This is a usage example of WikiPluginCached. |
30 // | You may copy this code freely under the conditions of the GPL |
31 // +---------------------------------------------------------------------+
33 /*------------------------------------------------------------------------
35 *------------------------------------------------------------------------
37 | You may call this plugin as follows:
39 | <<CacheTest text="What a wonderful test!" >>
42 /*-----------------------------------------------------------------------
46 *----------------------------------------------------------------------*/
48 /*-----------------------------------------------------------------------
49 | WikiPlugin_CacheTest
50 *----------------------------------------------------------------------*/
52 require_once 'lib/WikiPluginCached.php';
54 class WikiPlugin_CacheTest
55 extends WikiPluginCached
57 /* --------- overwrite virtual or abstract methods ---------------- */
59 function getPluginType()
61 return PLUGIN_CACHED_IMG_ONDEMAND;
69 function getDescription()
71 return 'This is a simple example using WikiPluginCached.';
74 function getDefaultArguments()
76 return array('text' => $this->getDescription(),
81 // should return image handle
83 // if an error occurs you MUST call
84 // $this->complain('aboutwhichidocomplain') you may produce an
85 // image handle to an error image if you do not,
86 // WikiPluginImageCache will do so.
88 function getImage($dbi, $argarray, $request)
91 return $this->produceGraphics($text, $font);
93 // This should also work
94 // return $this->lazy_produceGraphics($text,$font);
97 function getImageType($dbi, $argarray, $request)
100 if (in_array($type, array('png', 'gif', 'jpg'))) {
106 function getAlt($dbi, $argarray, $request)
108 // ALT-text for <img> tag
113 function getExpire($dbi, $argarray, $request)
115 return '+600'; // 600 seconds life time
118 /* -------------------- extremely simple converter -------------------- */
120 function produceGraphics($text, $font)
122 // The idea (and some code) is stolen from the text2png plugin
123 // but I did not want to use TTF. ImageString is quite ugly
124 // and quite compatible. It's only a usage example.
126 if ($font < 1 || $font > 5) {
127 $text = "Fontnr. (font=\"$font\") should be in range 1-5";
128 $this->complain($text);
132 $ok = ($im = @ImageCreate(400, 40));
133 $bg_color = ImageColorAllocate($im, 240, 240, 240);
134 $text_color1 = ImageColorAllocate($im, 120, 120, 120);
135 $text_color2 = ImageColorAllocate($im, 0, 0, 0);
137 ImageFilledRectangle($im, 0, 0, 149, 49, $bg_color);
138 ImageString($im, $font, 11, 12, $text, $text_color1);
139 ImageString($im, $font, 10, 10, $text, $text_color2);
142 // simple error handling by WikiPluginImageCache
143 $this->complain("Could not create image");
147 // image creation takes really _much_ time :-)
148 // so caching is very useful!
152 } // produce_Graphics
154 /* -------------------------------------------------------------------- */
156 // we could have used the simple built-in text2img function
157 // instead of writing our own:
159 function lazy_produceGraphics($text, $font)
161 if ($font < 1 || $font > 5) {
162 $text = "Fontnr. (font=\"$font\") should be in range 1-5";
163 $this->complain($text);
168 return $this->text2img($text, $font, array(0, 0, 0),
169 array(255, 255, 255));
170 } // lazy_produceGraphics
178 // c-hanging-comment-ender-p: nil
179 // indent-tabs-mode: nil