From: Carsten K. <car...@us...> - 2001-12-26 13:57:17
|
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory usw-pr-cvs1:/tmp/cvs-serv27140/phpwiki/lib/plugin Modified Files: text2png.php Log Message: Updated to use ErrorManager Index: text2png.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/text2png.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** text2png.php 2001/12/16 18:33:25 1.5 --- text2png.php 2001/12/26 13:57:14 1.6 *************** *** 1,4 **** --- 1,8 ---- <?php // -*-php-*- + /** + * File loading and saving diagnostic messages, to see whether an + * image was saved to or loaded from the cache and what the path is + */ define('text2png_debug', true); *************** *** 10,86 **** return "text2png"; } ! ! function getDefaultArguments() { global $LANG; ! 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"; 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 umask($oldumask); } ! // 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."); ! ! // 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) ! ! //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); ! ! //maybe 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 save to file: $success = ImagePng($im, $filepath . $filename); --- 14,96 ---- return "text2png"; } ! ! function getDefaultArguments() { global $LANG; ! 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 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); ! // permissions affected by user the www server is running as ! mkdir($filepath, 0777); umask($oldumask); } ! // add trailing slash to save some keystrokes later $filepath .= "/"; ! /* 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"; ! ! /* 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 text ! $text_color = ImageColorAllocate($im, 0, 0, 0); ! ImageTTFText($im, 10, 0, 10, 30, $text_color, $ttfont, $text); ! ! /* 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 save to file: $success = ImagePng($im, $filepath . $filename); *************** *** 90,112 **** } ! // create an <img src= tag to show the image! ! // this could use some better error reporting ! $html = ""; ! if ($success > 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" ; ! } } $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; ! } }; --- 100,124 ---- } ! // create an <img src= tag to show the image! ! $html = ""; ! if ($success > 0) { if (defined('text2png_debug')) { ! 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 { ! trigger_error(sprintf(_("couldn't open file '%s' for writing"), ! $filepath . $filename), E_USER_NOTICE); ! } ! return $html; ! } }; *************** *** 119,121 **** // indent-tabs-mode: nil // End: ! ?> --- 131,133 ---- // indent-tabs-mode: nil // End: ! ?> \ No newline at end of file |