From 1a71b770103d8a3d5a687ac09a5fdc96b73df586 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 7 May 2021 14:57:29 -0400 Subject: [PATCH] Add PR #163 small fixes in PWPNG class Co-authored-by: horst-n --- wire/core/PWPNG.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wire/core/PWPNG.php b/wire/core/PWPNG.php index 7fd20668..b5d0db54 100644 --- a/wire/core/PWPNG.php +++ b/wire/core/PWPNG.php @@ -25,7 +25,7 @@ class PWPNG { public function loadFile($lpszFileName) { // READ FILE if(!($fh = @fopen($lpszFileName, 'rb'))) { - $this->Error('Can\'t open image file: '.$file); + $this->Error('Can\'t open image file: '.basename($lpszFileName)); return false; } $ret = (false === $this->_parsepngstream($fh, basename($lpszFileName))) ? false : true; @@ -59,6 +59,7 @@ class PWPNG { $colspace = 'Indexed'; } else { $this->Error('Unknown color type: '.$file); + $colspace = ''; } if(ord($this->_readstream($f, 1)) != 0) $this->Error('Unknown compression method: '.$file); if(ord($this->_readstream($f, 1)) != 0) $this->Error('Unknown filter method: '.$file); @@ -114,7 +115,7 @@ class PWPNG { 'channels' => $ct, 'bits' => $bpc, 'dp' => $dp, - 'palette' => utf8_encode($pal), + 'palette' => (function_exists('utf8_encode') ? utf8_encode($pal) : $pal), 'trans' => $trns, 'alpha' => $ct >= 4 ? true : false, 'interlace' => $interlaced, @@ -131,7 +132,7 @@ class PWPNG { $s = fread($f, $n); if($s === false) { $this->Error('Error while reading stream'); - return; + return ''; } $n -= strlen($s); $res .= $s;