From d8b3e2ecf4e2fb94c03fae6803fc412ce34e4989 Mon Sep 17 00:00:00 2001 From: carstenklapp Date: Wed, 26 Dec 2001 13:57:14 +0000 Subject: [PATCH] Updated to use ErrorManager git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@887 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- lib/plugin/text2png.php | 156 +++++++++++++++++++++------------------- 1 file changed, 84 insertions(+), 72 deletions(-) diff --git a/lib/plugin/text2png.php b/lib/plugin/text2png.php index 30faae602..273affac0 100644 --- a/lib/plugin/text2png.php +++ b/lib/plugin/text2png.php @@ -1,5 +1,9 @@ "Hello WikiWorld!", + return array('text' => "Hello WikiWorld!", 'l' => $LANG ); - } - - function run($dbi, $argstr, $request) { - extract($this->getArgs($argstr, $request)); - return $this->text2png($text,$l); - } - - function text2png($text,$l) { - - //basic image creation and caching - //you MUST delete the image cache yourself if you change the drawing routines! - - //uncomment debug string above to see whether image was saved to or loaded from cache - //and what the path is. - - //locale test - //http://download.php.net/manual/en/function.dcgettext.php - //dcgettext and dgettext aren't available functions on my system.?? -carsten - //this doesn't seem to work anyway, always get english. ?? - //$oldlang=$LANG; - //putenv("LANG=$l"); - //$LANG=$l; - //if (!$l == "C") {include("locale/$l/LC_MESSAGES/phpwiki.php");} - //$text = gettext($text); - //putenv("LANG=$oldlang"); - - $filename = $text . ".png"; - - if ($l == "C") { $l = "en"; } //FIXME: hack for english, C=en ?? - $filepath = getcwd() . "/images/$l"; + } + + function run($dbi, $argstr, $request) { + extract($this->getArgs($argstr, $request)); + return $this->text2png($text,$l); + } + + function text2png($text,$l) { + + /** + * Basic image creation and caching + * You MUST delete the image cache yourself in /images if you change the + * drawing routines! + */ + + $filename = $text . ".png"; + + /* FIXME: need something more elegant, and a way to gettext a different + * language depending on any individual user's locale preferences. + */ + if ($l == "C") { $l = "en"; } //english=C + $filepath = getcwd() . "/images/$l"; if (!file_exists($filepath ."/". $filename)) { if (!file_exists($filepath)) { - $oldumask = umask(0); - mkdir($filepath, 0777); //permissions affected by user the www server is running as + $oldumask = umask(0); + // permissions affected by user the www server is running as + mkdir($filepath, 0777); umask($oldumask); } - // add trailing slash to save some keystrokes later + // add trailing slash to save some keystrokes later $filepath .= "/"; - // prepare a new image - $im = @ImageCreate(150, 50) or die ("Cannot Initialize new GD image stream. PHP must be compiled with support for GD 1.6 or later to create png files."); + /* prepare a new image + * FIXME: needs a dynamic image size depending on text width and height + * $im = @ImageCreate(150, 50); + */ + if (empty($im)) { + $error_text = _("Unable to create a new GD image stream. PHP must be compiled with support for the GD library version 1.6 or later to create PNG image files."); + // FIXME: Error manager does not transform URLs passed through it. + $error_text .= QElement('a', array('href' => "http://www.php.net/manual/en/function.imagecreate.php", + 'class' => 'rawurl'), "PHP web page"); + trigger_error( $error_text, E_USER_NOTICE ); + } + // get ready to draw + $bg_color = ImageColorAllocate($im, 255, 255, 255); + $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf"; - // get ready to draw - $bg_color = ImageColorAllocate($im, 255, 255, 255); - $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf"; + /* http://download.php.net/manual/en/function.imagettftext.php + * array imagettftext (int im, int size, int angle, int x, int y, int col, + * string fontfile, string text) + */ - // http://download.php.net/manual/en/function.imagettftext.php - // array imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, string text) + // draw shadow + $text_color = ImageColorAllocate($im, 175, 175, 175); + // shadow is 1 pixel down and 2 pixels right + ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text); - //draw shadow - $text_color = ImageColorAllocate($im, 175, 175, 175); - //shadow is 1 pixel down and 2 pixels right - ImageTTFText($im, 10, 0, 12, 31, $text_color, $ttfont, $text); - //draw text - $text_color = ImageColorAllocate($im, 0, 0, 0); - ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text); + // draw text + $text_color = ImageColorAllocate($im, 0, 0, 0); + ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text); - //maybe an alternate text drawing method in case ImageTTFText doesn't work - //ImageString($im, 2, 10, 40, $text, $text_color); + /* An alternate text drawing method in case ImageTTFText + * doesn't work. + */ + #ImageString($im, 2, 10, 40, $text, $text_color); - // to dump directly to browser: - //header("Content-type: image/png"); - //ImagePng($im); + // To dump directly to browser: + #header("Content-type: image/png"); + #ImagePng($im); - // to save to file: + // to save to file: $success = ImagePng($im, $filepath . $filename); } else { @@ -89,25 +99,27 @@ extends WikiPlugin $success = 2; } - // create an 0) { + // create an 0) { if (defined('text2png_debug')) { - switch($success) { - case 1: - $html .= Element('p', "Image saved to cache file: " . $filepath . $filename) . "\n" ; - case 2: - $html .= Element('p', "Image loaded from cache file: " . $filepath . $filename) . "\n" ; - } + switch($success) { + case 1: + trigger_error(sprintf(_("Image saved to cache file: %s"), + $filepath . $filename), E_USER_NOTICE); + case 2: + trigger_error(sprintf(_("Image loaded from cache file: %s"), + $filepath . $filename), E_USER_NOTICE); + } } $urlpath = DATA_PATH . "/images/$l/"; $html .= Element('img', array('src' => $urlpath . $filename, 'alt' => $text)); - } else { - $html .= Element('p', "Error writing png file: " . $filepath . $filename) . "\n"; - } - return $html; - } + } else { + trigger_error(sprintf(_("couldn't open file '%s' for writing"), + $filepath . $filename), E_USER_NOTICE); + } + return $html; + } }; // For emacs users @@ -118,4 +130,4 @@ extends WikiPlugin // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: -?> +?> \ No newline at end of file -- 2.45.0