From: <var...@us...> - 2021-06-28 14:45:45
|
Revision: 10335 http://sourceforge.net/p/phpwiki/code/10335 Author: vargenau Date: 2021-06-28 14:45:46 +0000 (Mon, 28 Jun 2021) Log Message: ----------- lib/plugin/text2png.php: better error handling Modified Paths: -------------- trunk/lib/plugin/text2png.php Modified: trunk/lib/plugin/text2png.php =================================================================== --- trunk/lib/plugin/text2png.php 2021-06-28 14:17:34 UTC (rev 10334) +++ trunk/lib/plugin/text2png.php 2021-06-28 14:45:46 UTC (rev 10335) @@ -84,10 +84,11 @@ } else { // we don't have png and/or gd. $error_html = _("Sorry, this version of PHP cannot create PNG image files."); - $link = "https://www.php.net/manual/pl/ref.image.php"; - $error_html .= sprintf(_("See %s"), $link) . "."; - trigger_error($error_html); - return HTML::p($error_html); + $error_html .= " "; + $error_html .= _("See") . _(": "); + $link = HTML::a(array('href' => "https://www.php.net/manual/en/ref.image.php"), + "https://www.php.net/manual/en/ref.image.php") ; + return HTML::span(array('class' => 'error'), $error_html, $link); } } @@ -147,7 +148,8 @@ if (defined('TTFONT')) $ttfont = TTFONT; elseif (PHP_OS == "Darwin") // Mac OS X - $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf"; elseif (isWindows()) { + $ttfont = "/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home/lib/fonts/LucidaSansRegular.ttf"; + elseif (isWindows()) { $ttfont = $_ENV['windir'] . '\Fonts\Arial.ttf'; } else { $ttfont = 'luximr'; // This is the only what sourceforge offered. @@ -161,15 +163,22 @@ // get ready to draw $s = imagettfbbox($fontsize, 0, $ttfont, $text); - $im = @imagecreate(abs($s[4]) + 20, abs($s[7]) + 10); + if ($s === false) { + $error_html = _("PHP was unable to create a new GD image stream. Read 'lib/plugin/text2png.php' for details."); + $error_html .= " "; + $error_html .= _("See") . _(": "); + $link = HTML::a(array('href' => "https://www.php.net/manual/en/function.imagecreate.php"), + "https://www.php.net/manual/en/function.imagecreate.php") ; + return HTML::span(array('class' => 'error'), $error_html, $link); + } + $im = imagecreate(abs($s[4]) + 20, abs($s[7]) + 10); if (empty($im)) { $error_html = _("PHP was unable to create a new GD image stream. Read 'lib/plugin/text2png.php' for details."); - // FIXME: Error manager does not transform URLs passed - // through it. - $link = "https://www.php.net/manual/en/function.imagecreate.php"; - $error_html .= sprintf(_("See %s"), $link) . "."; - trigger_error($error_html); - return HTML::p($error_html); + $error_html .= " "; + $error_html .= _("See") . _(": "); + $link = HTML::a(array('href' => "https://www.php.net/manual/en/function.imagecreate.php"), + "https://www.php.net/manual/en/function.imagecreate.php") ; + return HTML::span(array('class' => 'error'), $error_html, $link); } $rgb = $this->hexcolor($backcolor, array(255, 255, 255)); $bg_color = imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]); @@ -220,8 +229,9 @@ 'alt' => $text, 'title' => '"' . $text . '"' . _(" produced by ") . $this->getName()))); } else { - trigger_error(sprintf(_("couldn't open file “%s” for writing"), - $filepath . $filename)); + return HTML::span(array('class' => 'error'), + sprintf(_("couldn't open file “%s” for writing"), + $filepath . $filename)); } return $html; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |