2 rcs_id('$Id: text2png.php,v 1.13 2004-02-17 12:11:36 rurban Exp $');
4 Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
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
19 along with PhpWiki; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * File loading and saving diagnostic messages, to see whether an
26 * image was saved to or loaded from the cache and what the path is
28 * PHP must be compiled with support for the GD library version 1.6 or
29 * later to create PNG image files:
31 * ./configure --with-gd
33 * See <http://www.php.net/manual/pl/ref.image.php> for more info.
35 define('text2png_debug', true);
38 class WikiPlugin_text2png
45 function getDescription() {
46 return _("Convert text into a png image using GD.");
49 function getVersion() {
50 return preg_replace("/[Revision: $]/", '',
51 "\$Revision: 1.13 $");
54 function getDefaultArguments() {
56 return array('text' => "Hello WikiWorld!",
60 function run($dbi, $argstr, &$request, $basepage) {
61 if (ImageTypes() & IMG_PNG) {
62 // we have gd & png so go ahead.
63 extract($this->getArgs($argstr, $request));
64 return $this->text2png($text,$l);
66 // we don't have png and/or gd.
67 $error_html = _("Sorry, this version of PHP cannot create PNG image files.");
68 $link = "http://www.php.net/manual/pl/ref.image.php";
69 $error_html .= sprintf(_("See %s"), $link) .".";
70 trigger_error($error_html, E_USER_NOTICE);
75 function text2png($text, $l) {
78 * Basic image creation and caching
80 * You MUST delete the image cache yourself in /images if you
81 * change the drawing routines!
84 $filename = $text . ".png";
87 * FIXME: need something more elegant, and a way to gettext a
88 * different language depending on any individual
89 * user's locale preferences.
95 $filepath = getcwd() . "/images/$l";
97 if (!file_exists($filepath ."/". $filename)) {
99 if (!file_exists($filepath)) {
100 $oldumask = umask(0);
101 // permissions affected by user the www server is running as
102 mkdir($filepath, 0777);
106 // add trailing slash to save some keystrokes later
110 * prepare a new image
112 * FIXME: needs a dynamic image size depending on text
115 $im = @ImageCreate(150, 50);
118 $error_html = _("PHP was unable to create a new GD image stream. Read 'lib/plugin/text2png.php' for details.");
119 // FIXME: Error manager does not transform URLs passed
121 $link = "http://www.php.net/manual/en/function.imagecreate.php";
122 $error_html .= sprintf(_("See %s"), $link) .".";
123 trigger_error( $error_html, E_USER_NOTICE );
127 $bg_color = ImageColorAllocate($im, 255, 255, 255);
128 $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf";
130 /* http://download.php.net/manual/en/function.imagettftext.php
131 * array imagettftext (int im, int size, int angle, int x, int y,
132 * int col, string fontfile, string text)
136 $text_color = ImageColorAllocate($im, 175, 175, 175);
137 // shadow is 1 pixel down and 2 pixels right
138 ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text);
141 $text_color = ImageColorAllocate($im, 0, 0, 0);
142 ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text);
145 * An alternate text drawing method in case ImageTTFText
148 //ImageString($im, 2, 10, 40, $text, $text_color);
150 // To dump directly to browser:
151 //header("Content-type: image/png");
155 $success = ImagePng($im, $filepath . $filename);
162 // create an <img src= tag to show the image!
165 if (defined('text2png_debug')) {
168 trigger_error(sprintf(_("Image saved to cache file: %s"),
169 $filepath . $filename),
172 trigger_error(sprintf(_("Image loaded from cache file: %s"),
173 $filepath . $filename),
177 $url = "images/$l/$filename";
178 if (defined('DATA_PATH'))
179 $url = DATA_PATH . "/$url";
180 $html->pushContent(HTML::img(array('src' => $url,
183 trigger_error(sprintf(_("couldn't open file '%s' for writing"),
184 $filepath . $filename), E_USER_NOTICE);
190 // $Log: not supported by cvs2svn $
191 // Revision 1.12 2003/02/22 19:21:47 dairiki
192 // If DATA_PATH is not defined (by user in index.php), then use
193 // relative URLs to data.
195 // Revision 1.11 2003/01/18 22:08:01 carstenklapp
197 // Reformatting & tabs to spaces;
198 // Added copyleft, getVersion, getDescription, rcs_id.
206 // c-hanging-comment-ender-p: nil
207 // indent-tabs-mode: nil