2 // +---------------------------------------------------------------------+
4 // +---------------------------------------------------------------------+
5 // | simple test of the WikiPluginCached class which provides a |
6 // | text to image conversion. |
7 // | This is a usage example of WikiPluginCached. |
9 // | Copyright (C) 2002 Johannes Große (Johannes Große) |
10 // | You may copy this code freely under the conditions of the GPL |
11 // +---------------------------------------------------------------------+
13 /*------------------------------------------------------------------------
15 *------------------------------------------------------------------------
17 | You may call this plugin as follows:
19 | <?plugin CacheTest text="What a wonderful test!" ?>
22 /*-----------------------------------------------------------------------
26 *----------------------------------------------------------------------*/
28 /*-----------------------------------------------------------------------
29 | WikiPlugin_CacheTest
30 *----------------------------------------------------------------------*/
32 require_once "lib/WikiPluginCached.php";
34 class WikiPlugin_CacheTest extends WikiPluginCached
36 /* --------- overwrite virtual or abstract methods ---------------- */
38 function getPluginType() {
39 return PLUGIN_CACHED_IMG_ONDEMAND;
46 function getDescription() {
47 return 'This is a simple example using WikiPluginCached.';
50 function getDefaultArguments() {
51 return array('text' => $this->getDescription(),
56 // should return image handle
57 // if an error occurs you MUST call $this->complain('aboutwhichidocomplain')
58 // you may produce an image handle to an error image
59 // if you do not, WikiPluginImageCache will do so.
61 function getImage($dbi, $argarray, $request) {
63 return $this->produceGraphics($text,$font);
65 // This should also work
66 // return $this->lazy_produceGraphics($text,$font);
70 function getImageType($dbi, $argarray, $request) {
72 if (in_array($type,array('png','gif','jpg'))) {
78 function getAlt($dbi, $argarray, $request) {
79 // ALT-text for <img> tag
84 function getExpire($dbi, $argarray, $request) {
85 return '+600'; // 600 seconds life time
89 /* -------------------- extremely simple converter -------------------- */
92 function produceGraphics($text, $font ) {
93 // The idea (and some code) is stolen from the text2png plugin
94 // but I did not want to use TTF. ImageString is quite ugly
95 // and quite compatible. It's only a usage example.
97 if ($font<1 || $font>5) {
98 $text = "Fontnr. (font=\"$font\") should be in range 1-5";
99 $this->complain($text);
103 $ok = ($im = @ImageCreate(400, 40));
104 $bg_color = ImageColorAllocate($im, 240, 240, 240);
105 $text_color1 = ImageColorAllocate($im, 120, 120, 120);
106 $text_color2 = ImageColorAllocate($im, 0, 0, 0);
108 ImageFilledRectangle($im, 0, 0, 149, 49, $bg_color);
109 ImageString($im, $font, 11, 12, $text, $text_color1);
110 ImageString($im, $font, 10, 10, $text, $text_color2);
113 // simple error handling by WikiPluginImageCache
114 $this->complain("Could not create image");
118 // image creation takes really _much_ time :-)
119 // so caching is very useful!
123 } // produce_Graphics
125 /* -------------------------------------------------------------------- */
127 // we could have used the simple built-in text2img function
128 // instead of writing our own:
130 function lazy_produceGraphics( $text, $font ) {
131 if ($font<1 || $font>5) {
132 $text = "Fontnr. (font=\"$font\") should be in range 1-5";
133 $this->complain($text);
137 return $this->text2img($text,$font,array(0,0,0),array(255,255,255));
138 } // lazy_produceGraphics
140 } // WikiPlugin_CacheTest
149 // c-hanging-comment-ender-p: nil
150 // indent-tabs-mode: nil