]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/text2png.php
New text2png WikiPlugin. Doesn't accept any arguments yet, just dumps a png image...
[SourceForge/phpwiki.git] / lib / plugin / text2png.php
1 <?php // -*-php-*-
2
3 class WikiPlugin_text2png
4 extends WikiPlugin
5 {
6     var $name = 'text2png';
7     function getDefaultArguments() {
8         return array('text'    => 'Hello WikiWorld!');
9     }
10    function run($args) {
11         //FIXME: are quotes needed for the argument string text= or no?
12         //FIXME: the next two lines aren't the correct way to extract a text argument for a WikiPlugin
13         $args = &$this->args;
14         $t = $args['text'];
15         return $this->text2png($t);
16         
17 //        return sprintf("<tt>%s %s</tt>", $salutation, $name);
18     }
19
20     function text2png($text) {
21         //FIXME: once this accepts a text argument the next line should be removed
22         $text="Hello WikiWorld!";
23         
24         $text or die ("?text string required");
25         $im = @ImageCreate(150, 75) or die ("Cannot Initialize new GD image stream. PHP must be compiled with support for GD 1.6 or later to create png files.");
26
27         $bg_color   = ImageColorAllocate($im, 255, 255, 255);
28         $text_color = ImageColorAllocate($im, 50, 50, 200);
29         $ttfont     = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
30
31         ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text);
32         ImageString($im, 2, 10, 40, $text, $text_color);
33
34         // dump directly to browser:
35         //        header("Content-type: image/png");
36         //        ImagePng($im);
37
38         // save to file:
39         $filename = $text . ".png";
40         $success = ImagePng($im, "../" . $filename);
41
42         //FIXME: the link generated doesn't work. The image file is dumped in the same directory as index.php
43         if($success = 1) {
44             $s = "<p>png image saved as <a href=\"/$filename\">$filename</a>.</p>";
45          } else {
46             $s = "<p>Error creating png file.</p>";
47         }  
48         return $s;
49     }
50 };
51
52 // For emacs users
53 // Local Variables:
54 // mode: php
55 // tab-width: 8
56 // c-basic-offset: 4
57 // c-hanging-comment-ender-p: nil
58 // indent-tabs-mode: nil
59 // End:
60 ?>