2 rcs_id('$Id: CacheTest.php,v 1.2 2003-01-18 21:19:25 carstenklapp Exp $');
3 // +---------------------------------------------------------------------+
5 // +---------------------------------------------------------------------+
6 // | simple test of the WikiPluginCached class which provides a |
7 // | text to image conversion. |
8 // | This is a usage example of WikiPluginCached. |
10 // | Copyright (C) 2002 Johannes Große (Johannes Große) |
11 // | You may copy this code freely under the conditions of the GPL |
12 // +---------------------------------------------------------------------+
14 /*------------------------------------------------------------------------
16 *------------------------------------------------------------------------
18 | You may call this plugin as follows:
20 | <?plugin CacheTest text="What a wonderful test!" ?>
23 /*-----------------------------------------------------------------------
27 *----------------------------------------------------------------------*/
29 /*-----------------------------------------------------------------------
30 | WikiPlugin_CacheTest
31 *----------------------------------------------------------------------*/
33 require_once "lib/WikiPluginCached.php";
35 class WikiPlugin_CacheTest
36 extends WikiPluginCached
38 /* --------- overwrite virtual or abstract methods ---------------- */
40 function getPluginType() {
41 return PLUGIN_CACHED_IMG_ONDEMAND;
48 function getDescription() {
49 return 'This is a simple example using WikiPluginCached.';
52 function getVersion() {
53 return preg_replace("/[Revision: $]/", '',
57 function getDefaultArguments() {
58 return array('text' => $this->getDescription(),
63 // should return image handle
65 // if an error occurs you MUST call
66 // $this->complain('aboutwhichidocomplain') you may produce an
67 // image handle to an error image if you do not,
68 // WikiPluginImageCache will do so.
70 function getImage($dbi, $argarray, $request) {
72 return $this->produceGraphics($text,$font);
74 // This should also work
75 // return $this->lazy_produceGraphics($text,$font);
79 function getImageType($dbi, $argarray, $request) {
81 if (in_array($type, array('png', 'gif', 'jpg'))) {
87 function getAlt($dbi, $argarray, $request) {
88 // ALT-text for <img> tag
93 function getExpire($dbi, $argarray, $request) {
94 return '+600'; // 600 seconds life time
98 /* -------------------- extremely simple converter -------------------- */
101 function produceGraphics($text, $font ) {
102 // The idea (and some code) is stolen from the text2png plugin
103 // but I did not want to use TTF. ImageString is quite ugly
104 // and quite compatible. It's only a usage example.
106 if ($font<1 || $font>5) {
107 $text = "Fontnr. (font=\"$font\") should be in range 1-5";
108 $this->complain($text);
112 $ok = ($im = @ImageCreate(400, 40));
113 $bg_color = ImageColorAllocate($im, 240, 240, 240);
114 $text_color1 = ImageColorAllocate($im, 120, 120, 120);
115 $text_color2 = ImageColorAllocate($im, 0, 0, 0);
117 ImageFilledRectangle($im, 0, 0, 149, 49, $bg_color);
118 ImageString($im, $font, 11, 12, $text, $text_color1);
119 ImageString($im, $font, 10, 10, $text, $text_color2);
122 // simple error handling by WikiPluginImageCache
123 $this->complain("Could not create image");
127 // image creation takes really _much_ time :-)
128 // so caching is very useful!
132 } // produce_Graphics
134 /* -------------------------------------------------------------------- */
136 // we could have used the simple built-in text2img function
137 // instead of writing our own:
139 function lazy_produceGraphics( $text, $font ) {
140 if ($font<1 || $font>5) {
141 $text = "Fontnr. (font=\"$font\") should be in range 1-5";
142 $this->complain($text);
147 return $this->text2img($text, $font, array(0, 0, 0),
148 array(255, 255, 255));
149 } // lazy_produceGraphics
151 } // WikiPlugin_CacheTest
153 // $Log: not supported by cvs2svn $
160 // c-hanging-comment-ender-p: nil
161 // indent-tabs-mode: nil