From f57a07e15a87860f928844c528a10ca94d76cc1c Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Thu, 29 Dec 2022 12:20:20 -0500 Subject: [PATCH] Attempt fix for processwire/processwire-issues#1299 using @adrianbj suggestion --- wire/core/ImageSizerEngineGD.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wire/core/ImageSizerEngineGD.php b/wire/core/ImageSizerEngineGD.php index 1881658a..d31b45a6 100755 --- a/wire/core/ImageSizerEngineGD.php +++ b/wire/core/ImageSizerEngineGD.php @@ -862,12 +862,13 @@ class ImageSizerEngineGD extends ImageSizerEngine { } else if($this->imageType == IMAGETYPE_GIF) { // @mrx GIF transparency $transparentIndex = imagecolortransparent($image); - // $transparentColor = $transparentIndex != -1 ? @imagecolorsforindex($image, $transparentIndex) : 0; - $transparentColor = $transparentIndex != -1 ? imagecolorsforindex($image, ($transparentIndex < imagecolorstotal($image) ? $transparentIndex : $transparentIndex - 1)) : 0; - if(!empty($transparentColor)) { - $transparentNew = imagecolorallocate($im, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']); - $transparentNewIndex = imagecolortransparent($im, $transparentNew); - imagefill($im, 0, 0, $transparentNewIndex); + if($transparentIndex >= 0 && $transparentIndex < imagecolorstotal($image)) { + $transparentColor = imagecolorsforindex($image, $transparentIndex); + if(!empty($transparentColor)) { + $transparentNew = imagecolorallocate($im, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue']); + $transparentNewIndex = imagecolortransparent($im, $transparentNew); + imagefill($im, 0, 0, $transparentNewIndex); + } } } else {