From 6f598964812fa94a1e5885ac8a09e884235a3a17 Mon Sep 17 00:00:00 2001 From: Maef Date: Tue, 25 Jul 2023 14:56:30 +0200 Subject: [PATCH] Update to phpThumb 1.7.21-202307141720 (#16456) --- core/model/phpthumb/phpthumb.class.php | 58 ++++++++++++---------- core/model/phpthumb/phpthumb.filters.php | 57 +++++++++++---------- core/model/phpthumb/phpthumb.functions.php | 33 +++++++++--- core/model/phpthumb/phpthumb.unsharp.php | 6 +-- 4 files changed, 95 insertions(+), 59 deletions(-) diff --git a/core/model/phpthumb/phpthumb.class.php b/core/model/phpthumb/phpthumb.class.php index 8fc80ed3175..ef70dd79ede 100644 --- a/core/model/phpthumb/phpthumb.class.php +++ b/core/model/phpthumb/phpthumb.class.php @@ -265,7 +265,7 @@ class phpthumb { public $issafemode = null; public $php_memory_limit = null; - public $phpthumb_version = '1.7.19-202210110924'; + public $phpthumb_version = '1.7.21-202307141720'; ////////////////////////////////////////////////////////////////////// @@ -314,6 +314,9 @@ public function __destruct() { $this->purgeTempFiles(); } + public function __set(string $name, mixed $value): void { + } + // public: public function purgeTempFiles() { foreach ($this->tempFilesToDelete as $tempFileToDelete) { @@ -1447,7 +1450,7 @@ public function ResolveFilenameToAbsolute($filename) { $AbsoluteFilename = str_replace(DIRECTORY_SEPARATOR, '/', $AbsoluteFilename); } $resolvedAbsoluteFilename = $this->resolvePath($AbsoluteFilename, $this->config_additional_allowed_dirs); - if (!$this->config_allow_src_above_docroot && !preg_match('#^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', $this->realPathSafe($this->config_document_root))).'#', $resolvedAbsoluteFilename)) { + if (!$this->config_allow_src_above_docroot && !preg_match('#^'.preg_quote(str_replace(DIRECTORY_SEPARATOR, '/', $this->realPathSafe($this->config_document_root))).'#', (string)$resolvedAbsoluteFilename)) { $this->DebugMessage('!$this->config_allow_src_above_docroot therefore setting "'.$AbsoluteFilename.'" (outside "'.$this->realPathSafe($this->config_document_root).'") to null', __FILE__, __LINE__); return false; } @@ -1492,7 +1495,8 @@ public function ImageMagickWhichConvert() { if (($cachedwhichconvertstring = @file_get_contents($IMwhichConvertCacheFilename)) !== false) { $WhichConvert = $cachedwhichconvertstring; } else { - $WhichConvert = trim(phpthumb_functions::SafeExec('which convert')); + $execResult = phpthumb_functions::SafeExec('which convert'); + $WhichConvert = $execResult !== null ? trim($execResult) : null; @file_put_contents($IMwhichConvertCacheFilename, $WhichConvert); @chmod($IMwhichConvertCacheFilename, $this->getParameter('config_file_create_mask')); } @@ -1800,7 +1804,7 @@ public function ImageMagickThumbnailToGD() { // some (older? around 2002) versions of IM won't accept "-resize 100x" but require "-resize 100x100" $commandline_test = $this->ImageMagickCommandlineBase().' logo: -resize 1x '.phpthumb_functions::escapeshellarg_replacement($IMtempfilename).' 2>&1'; $IMresult_test = phpthumb_functions::SafeExec($commandline_test); - $IMuseExplicitImageOutputDimensions = preg_match('#image dimensions are zero#i', $IMresult_test); + $IMuseExplicitImageOutputDimensions = preg_match('#image dimensions are zero#i', (string)$IMresult_test); $this->DebugMessage('IMuseExplicitImageOutputDimensions = '. (int) $IMuseExplicitImageOutputDimensions, __FILE__, __LINE__); if ($fp_im_temp = @fopen($IMtempfilename, 'wb')) { // erase temp image so ImageMagick logo doesn't get output if other processing fails @@ -1986,8 +1990,8 @@ public function ImageMagickThumbnailToGD() { } } list($nw, $nh) = phpthumb_functions::TranslateWHbyAngle($this->w, $this->h, $this->ra); - $nw = ((round($nw) != 0) ? round($nw) : ''); - $nh = ((round($nh) != 0) ? round($nh) : ''); + $nw = ((isset($nw) && round($nw) != 0) ? round($nw) : ''); + $nh = ((isset($nh) && round($nh) != 0) ? round($nh) : ''); $commandline .= ' -'.$IMresizeParameter.' '.phpthumb_functions::escapeshellarg_replacement($nw.'x'.$nh); } @@ -2019,7 +2023,7 @@ public function ImageMagickThumbnailToGD() { if (($this->ra % 90) != 0) { if (preg_match('#('.implode('|', $this->AlphaCapableFormats).')#i', $outputFormat)) { // alpha-capable format - $commandline .= ' -background rgba(255,255,255,0)'; + $commandline .= ' -background '.phpthumb_functions::escapeshellarg_replacement('rgba(255,255,255,0)'); } else { $commandline .= ' -background '.phpthumb_functions::escapeshellarg_replacement('#'.($this->bg ? $this->bg : 'FFFFFF')); } @@ -2188,9 +2192,9 @@ public function ImageMagickThumbnailToGD() { case 'lvl': @list($band, $method, $threshold) = explode('|', $parameter); - $band = ($band ? preg_replace('#[^RGBA\\*]#', '', strtoupper($band)) : '*'); - $method = ((strlen($method) > 0) ? (int) $method : 2); - $threshold = ((strlen($threshold) > 0) ? min(max((float) $threshold, 0), 100) : 0.1); + $band = ($band ? preg_replace('#[^RGBA\\*]#', '', strtoupper((string)$band)) : '*'); + $method = ((strlen((string)$method) > 0) ? (int) $method : 2); + $threshold = ((strlen((string)$threshold) > 0) ? min(max((float) $threshold, 0), 100) : 0.1); $band = preg_replace('#[^RGBA\\*]#', '', strtoupper($band)); @@ -2395,6 +2399,10 @@ public function ImageMagickThumbnailToGD() { } } } + // ImageMagic also support quality for webp - but only for version 7.0.8-68 and above + if (($outputFormat=='webp') && $this->q && $this->ImageMagickSwitchAvailable(['quality'])) { + $commandline .= ' -quality '.phpthumb_functions::escapeshellarg_replacement($this->thumbnailQuality); + } $commandline .= ' '.$outputFormat.':'.phpthumb_functions::escapeshellarg_replacement($IMtempfilename); if (!$this->iswindows) { $commandline .= ' 2>&1'; @@ -2403,8 +2411,8 @@ public function ImageMagickThumbnailToGD() { $IMresult = phpthumb_functions::SafeExec($commandline); clearstatcache(); if (!@file_exists($IMtempfilename) || !@filesize($IMtempfilename)) { - $this->FatalError('ImageMagick failed with message ('.trim($IMresult).')'); - $this->DebugMessage('ImageMagick failed with message ('.trim($IMresult).')', __FILE__, __LINE__); + $this->FatalError('ImageMagick failed with message ('.trim((string)$IMresult).')'); + $this->DebugMessage('ImageMagick failed with message ('.trim((string)$IMresult).')', __FILE__, __LINE__); if ($this->iswindows && !$IMresult) { $this->DebugMessage('Check to make sure that PHP has read+write permissions to "'.dirname($IMtempfilename).'"', __FILE__, __LINE__); } @@ -2630,7 +2638,7 @@ public function AntiOffsiteLinking() { } } - if ($allow && $this->config_nohotlink_enabled && preg_match('#^(f|ht)tps?\://#i', $this->src)) { + if ($allow && $this->config_nohotlink_enabled && preg_match('#^(f|ht)tps?\://#i', (string)$this->src)) { $parsed_url = phpthumb_functions::ParseURLbetter($this->src); //if (!phpthumb_functions::CaseInsensitiveInArray(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) { if (!$this->OffsiteDomainIsAllowed(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) { @@ -2894,8 +2902,8 @@ public function ApplyFilters() { case 'lvl': // autoLevels @list($band, $method, $threshold) = explode('|', $parameter, 3); $band = ($band ? preg_replace('#[^RGBA\\*]#', '', strtoupper($band)) : '*'); - $method = ((strlen($method) > 0) ? (int) $method : 2); - $threshold = ((strlen($threshold) > 0) ? (float) $threshold : 0.1); + $method = ((strlen((string)$method) > 0) ? (int) $method : 2); + $threshold = ((strlen((string)$threshold) > 0) ? (float) $threshold : 0.1); $phpthumbFilters->HistogramStretch($this->gdimg_output, $band, $method, $threshold); break; @@ -3002,8 +3010,8 @@ public function ApplyFilters() { case 'over': // Overlay @list($filename, $underlay, $margin, $opacity) = explode('|', $parameter, 4); $underlay = (bool) ($underlay ? $underlay : false); - $margin = ((strlen($margin) > 0) ? $margin : ($underlay ? 0.1 : 0.0)); - $opacity = ((strlen($opacity) > 0) ? $opacity : 100); + $margin = ((strlen((string)$margin) > 0) ? $margin : ($underlay ? 0.1 : 0.0)); + $opacity = ((strlen((string)$opacity) > 0) ? $opacity : 100); if (($margin > 0) && ($margin < 1)) { $margin = min(0.499, $margin); } elseif (($margin > -1) && ($margin < 0)) { @@ -3477,15 +3485,15 @@ public function SetOrientationDependantWidthHeight() { public function ExtractEXIFgetImageSize() { $this->DebugMessage('starting ExtractEXIFgetImageSize()', __FILE__, __LINE__); - if (preg_match('#^http:#i', $this->src) && !$this->sourceFilename && $this->rawImageData) { + if (preg_match('#^http:#i', (string)$this->src) && !$this->sourceFilename && $this->rawImageData) { $this->SourceDataToTempFile(); } if (null === $this->getimagesizeinfo) { if ($this->sourceFilename) { if ($this->getimagesizeinfo = @getimagesize($this->sourceFilename)) { - $this->source_width = $this->getimagesizeinfo[0]; - $this->source_height = $this->getimagesizeinfo[1]; - $this->DebugMessage('getimagesize('.$this->sourceFilename.') says image is '.$this->source_width.'x'.$this->source_height, __FILE__, __LINE__); + $this->source_width = $this->getimagesizeinfo[0]; + $this->source_height = $this->getimagesizeinfo[1]; + $this->DebugMessage('getimagesize('.$this->sourceFilename.') says image is '.$this->source_width.'x'.$this->source_height, __FILE__, __LINE__); } else { $this->DebugMessage('getimagesize('.$this->sourceFilename.') failed', __FILE__, __LINE__); } @@ -3682,8 +3690,8 @@ public function SetCacheFilename() { $broad_directory_name = strtolower(md5($this->rawImageData)); $this->cache_filename .= '_raw'.$broad_directory_name; } else { - $this->DebugMessage('SetCacheFilename() _src set from md5($this->sourceFilename) "'.$this->sourceFilename.'" = "'.md5($this->sourceFilename).'"', __FILE__, __LINE__); - $broad_directory_name = strtolower(md5($this->sourceFilename)); + $this->DebugMessage('SetCacheFilename() _src set from md5($this->sourceFilename) "'.$this->sourceFilename.'" = "'.md5((string)$this->sourceFilename).'"', __FILE__, __LINE__); + $broad_directory_name = strtolower(md5((string)$this->sourceFilename)); $this->cache_filename .= '_src'.$broad_directory_name; } if (!empty($_SERVER['HTTP_REFERER']) && $this->config_nooffsitelink_enabled) { @@ -3717,8 +3725,8 @@ public function SetCacheFilename() { $ParametersString .= '_'.$key.substr(md5($this->$key), 0, 4); } } - if ($this->thumbnailFormat == 'jpeg') { - // only JPEG output has variable quality option + if (in_array($this->thumbnailFormat, ['jpeg','webp'])) { + // only JPEG and WEBP output has variable quality option $ParametersString .= '_q'. (int) $this->thumbnailQuality; } $this->DebugMessage('SetCacheFilename() _par set from md5('.$ParametersString.')', __FILE__, __LINE__); diff --git a/core/model/phpthumb/phpthumb.filters.php b/core/model/phpthumb/phpthumb.filters.php index a18b7399de7..9606476b454 100644 --- a/core/model/phpthumb/phpthumb.filters.php +++ b/core/model/phpthumb/phpthumb.filters.php @@ -114,15 +114,15 @@ public function Blur(&$gdimg, $radius=0.5) { // Move copies of the image around one pixel at the time and merge them with weight // according to the matrix. The same matrix is simply repeated for higher radii. for ($i = 0; $i < $radius; $i++) { - imagecopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1); // up left - imagecopymerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50.00000); // down right - imagecopymerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33.33333); // down left - imagecopymerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25.00000); // up right - imagecopymerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33.33333); // left - imagecopymerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25.00000); // right - imagecopymerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20.00000); // up - imagecopymerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 16.666667); // down - imagecopymerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50.000000); // center + imagecopy ($imgBlur, $gdimg, 0, 0, 1, 1, $w - 1, $h - 1); // up left + imagecopymerge($imgBlur, $gdimg, 1, 1, 0, 0, $w, $h, 50); // down right + imagecopymerge($imgBlur, $gdimg, 0, 1, 1, 0, $w - 1, $h, 33); // down left + imagecopymerge($imgBlur, $gdimg, 1, 0, 0, 1, $w, $h - 1, 25); // up right + imagecopymerge($imgBlur, $gdimg, 0, 0, 1, 0, $w - 1, $h, 33); // left + imagecopymerge($imgBlur, $gdimg, 1, 0, 0, 0, $w, $h, 25); // right + imagecopymerge($imgBlur, $gdimg, 0, 0, 0, 1, $w, $h - 1, 20); // up + imagecopymerge($imgBlur, $gdimg, 0, 1, 0, 0, $w, $h, 17); // down + imagecopymerge($imgBlur, $gdimg, 0, 0, 0, 0, $w, $h, 50); // center imagecopy ($gdimg, $imgBlur, 0, 0, 0, 0, $w, $h); } return true; @@ -287,8 +287,10 @@ public function Crop(&$gdimg, $left=0, $right=0, $top=0, $bottom=0) { if (($bottom > 0) && ($bottom < 1)) { $bottom = round($bottom * $oldH); } $right = min($oldW - $left - 1, $right); $bottom = min($oldH - $top - 1, $bottom); - $newW = $oldW - $left - $right; - $newH = $oldH - $top - $bottom; + $newW = (int)($oldW - $left - $right); + $newH = (int)($oldH - $top - $bottom); + $left = (int)$left; + $top = (int)$top; if ($imgCropped = imagecreatetruecolor($newW, $newH)) { imagecopy($imgCropped, $gdimg, 0, 0, $left, $top, $newW, $newH); @@ -362,8 +364,8 @@ public function DropShadow(&$gdimg, $distance, $width, $hexcolor, $angle, $alpha //for ($i = 0; $i < $width; $i++) { for ($i = 0; $i < 1; $i++) { if (!isset($PixelMap[$x][$y]['alpha']) || ($PixelMap[$x][$y]['alpha'] > 0)) { - if (isset($PixelMap[$x + $Offset['x']][$y + $Offset['y']]['alpha']) && ($PixelMap[$x + $Offset['x']][$y + $Offset['y']]['alpha'] < 127)) { - $thisColor = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor, false, $PixelMap[$x + $Offset['x']][$y + $Offset['y']]['alpha']); + if (isset($PixelMap[$x + (int)$Offset['x']][$y + (int)$Offset['y']]['alpha']) && ($PixelMap[$x + (int)$Offset['x']][$y + (int)$Offset['y']]['alpha'] < 127)) { + $thisColor = phpthumb_functions::ImageHexColorAllocate($gdimg, $hexcolor, false, $PixelMap[$x + (int)$Offset['x']][$y + (int)$Offset['y']]['alpha']); imagesetpixel($gdimg_dropshadow_temp, $x, $y, $thisColor); } } @@ -1018,7 +1020,7 @@ public function SourceTransparentColorMask(&$gdimg, $hexcolor, $min_limit=5, $ma for ($y = 0; $y < $height; $y++) { $currentPixel = phpthumb_functions::GetPixelColor($gdimg, $x, $y); $colorDiff = phpthumb_functions::PixelColorDifferencePercent($currentPixel, $targetPixel); - $grayLevel = min($cutoffRange, max(0, -$min_limit + $colorDiff)) * (255 / max(1, $cutoffRange)); + $grayLevel = (int)min($cutoffRange, max(0, -$min_limit + $colorDiff)) * (255 / max(1, $cutoffRange)); $newColor = imagecolorallocate($gdimg_mask, $grayLevel, $grayLevel, $grayLevel); imagesetpixel($gdimg_mask, $x, $y, $newColor); } @@ -1127,16 +1129,20 @@ public function WatermarkText(&$gdimg, $text, $size, $alignment, $hex_color='000 } $lineheight = min(100.0, max(0.01, (float) $lineheight)); - $metaTextArray = array( - '^Fb' => $this->phpThumbObject->getimagesizeinfo['filesize'], - '^Fk' => round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1024), - '^Fm' => round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1048576), - '^X' => $this->phpThumbObject->getimagesizeinfo[0], - '^Y' => $this->phpThumbObject->getimagesizeinfo[1], - '^x' => imagesx($gdimg), - '^y' => imagesy($gdimg), - '^^' => '^', - ); + $metaTextArray = array(); + if (is_array($this->phpThumbObject->getimagesizeinfo)) { + if (array_key_exists('filesize',$this->phpThumbObject->getimagesizeinfo)) { + $metaTextArray['^Fb'] = $this->phpThumbObject->getimagesizeinfo['filesize']; + $metaTextArray['^Fk'] = round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1024); + $metaTextArray['^Fm'] = round($this->phpThumbObject->getimagesizeinfo['filesize'] / 1048576); + } + $metaTextArray['^X'] = $this->phpThumbObject->getimagesizeinfo[0]; + $metaTextArray['^Y'] = $this->phpThumbObject->getimagesizeinfo[1]; + } + $metaTextArray['^x'] = imagesx($gdimg); + $metaTextArray['^y'] = imagesy($gdimg); + $metaTextArray['^^'] = '^'; + $text = strtr($text, $metaTextArray); $text = str_replace(array( @@ -1430,7 +1436,8 @@ public function WatermarkOverlay(&$gdimg_dest, &$img_watermark, $alignment='*', $watermark_source_width = imagesx($img_watermark); $watermark_source_height = imagesy($img_watermark); $watermark_opacity_percent = max(0, min(100, $opacity)); - $margin_y = (null === $margin_y ? $margin_x : $margin_y); + $margin_x = (null === $margin_x ? 0 : $margin_y); // if null fill 0 (or 5?) + $margin_y = (null === $margin_y ? $margin_x : $margin_y); $watermark_margin_x = ((($margin_x > 0) && ($margin_x < 1)) ? round((1 - $margin_x) * $img_source_width) : $margin_x); $watermark_margin_y = ((($margin_y > 0) && ($margin_y < 1)) ? round((1 - $margin_y) * $img_source_height) : $margin_y); $watermark_destination_x = 0; diff --git a/core/model/phpthumb/phpthumb.functions.php b/core/model/phpthumb/phpthumb.functions.php index f74c2c2bab9..acde62d10fb 100644 --- a/core/model/phpthumb/phpthumb.functions.php +++ b/core/model/phpthumb/phpthumb.functions.php @@ -232,13 +232,13 @@ public static function HexCharDisplay($string) { public static function IsHexColor($HexColorString) { - return preg_match('#^[0-9A-F]{6}$#i', $HexColorString); + return preg_match('#^[0-9A-F]{6}$#i', (string)$HexColorString); } public static function ImageColorAllocateAlphaSafe(&$gdimg_hexcolorallocate, $R, $G, $B, $alpha=false) { if (self::version_compare_replacement(PHP_VERSION, '4.3.2', '>=') && ($alpha !== false)) { - return imagecolorallocatealpha($gdimg_hexcolorallocate, $R, $G, $B, (int) $alpha); + return imagecolorallocatealpha($gdimg_hexcolorallocate, round($R), round($G), round($B), (int) $alpha); } else { return imagecolorallocate($gdimg_hexcolorallocate, $R, $G, $B); } @@ -706,7 +706,7 @@ public static function CleanUpURLencoding($url, $queryseperator='&') { return $url; } $parsed_url = self::ParseURLbetter($url); - $pathelements = explode('/', $parsed_url['path']); + $pathelements = explode('/', (string)$parsed_url['path']); $CleanPathElements = array(); $TranslationMatrix = array(' '=>'%20'); foreach ($pathelements as $key => $pathelement) { @@ -718,7 +718,7 @@ public static function CleanUpURLencoding($url, $queryseperator='&') { } } - $queries = explode($queryseperator, $parsed_url['query']); + $queries = explode($queryseperator, (string)$parsed_url['query']); $CleanQueries = array(); foreach ($queries as $key => $query) { @list($param, $value) = explode('=', $query); @@ -862,6 +862,16 @@ public static function EnsureDirectoryExists($dirname, $mask=0755) { $delimiter = ':'; $case_insensitive_pathname = false; } + do { + /* + \\3930K\WEBROOT\trainspotted.com\phpThumb/_cache/\6\6f // starts off with mismatched directory separators + \\3930K\WEBROOT\trainspotted.com\phpThumb\_cache\\6\6f // gets multiple directory separators in a row that we want to strip out (being sure not to replace the UNC double-slash at the beginning) + */ + if ($doubleslash_offset = strpos($dirname, DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, 1)) { + $dirname = substr($dirname, 0, $doubleslash_offset).substr($dirname, $doubleslash_offset + 1); + } + } while ($doubleslash_offset !== false); + $open_basedirs = explode($delimiter, $config_open_basedir); foreach ($open_basedirs as $key => $open_basedir) { if (preg_match('#^'.preg_quote($open_basedir).'#'.($case_insensitive_pathname ? 'i' : ''), $dirname) && (strlen($dirname) > strlen($open_basedir))) { @@ -878,12 +888,23 @@ public static function EnsureDirectoryExists($dirname, $mask=0755) { continue; } if (!@is_dir($test_directory)) { + if (substr($test_directory, 0, 2) == '\\\\') { + // UNC path + if (count(explode('\\', $test_directory)) <= 4) { + // 1,2 = UNC starting slashes + // 3 = hostname; skip further checks + // 4 = sharename; skip further checks + // 5+ = real subdiretories + continue; + } + } if (@file_exists($test_directory)) { // directory name already exists as a file return false; } @mkdir($test_directory, $mask); @chmod($test_directory, $mask); + clearstatcache(); if (!@is_dir($test_directory) || !@is_writable($test_directory)) { return false; } @@ -1049,8 +1070,8 @@ function preg_quote($string, $delimiter='\\') { if (!function_exists('file_get_contents')) { // included in PHP v4.3.0+ function file_get_contents($filename) { - if (preg_match('#^(f|ht)tp\://#i', $filename)) { - return SafeURLread($filename, $error); + if (preg_match('#^(ftp|https?)\://#i', $filename)) { + return phpthumb_functions::SafeURLread($filename, $error); } if ($fp = @fopen($filename, 'rb')) { $rawData = ''; diff --git a/core/model/phpthumb/phpthumb.unsharp.php b/core/model/phpthumb/phpthumb.unsharp.php index a5c454ee1f5..3802e8bf904 100644 --- a/core/model/phpthumb/phpthumb.unsharp.php +++ b/core/model/phpthumb/phpthumb.unsharp.php @@ -110,9 +110,9 @@ public static function applyUnsharpMask(&$img, $amount, $radius, $threshold) { // When the masked pixels differ less from the original // than the threshold specifies, they are set to their original value. - $rNew = ((abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig); - $gNew = ((abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig); - $bNew = ((abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig); + $rNew = (int)((abs($rOrig - $rBlur) >= $threshold) ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig); + $gNew = (int)((abs($gOrig - $gBlur) >= $threshold) ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig); + $bNew = (int)((abs($bOrig - $bBlur) >= $threshold) ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig); if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) { $pixCol = imagecolorallocate($img, $rNew, $gNew, $bNew);