diff --git a/src/Drivers/Gd/Modifiers/ResizeModifier.php b/src/Drivers/Gd/Modifiers/ResizeModifier.php index b030a8e3..7646a22f 100644 --- a/src/Drivers/Gd/Modifiers/ResizeModifier.php +++ b/src/Drivers/Gd/Modifiers/ResizeModifier.php @@ -44,15 +44,14 @@ class ResizeModifier implements ModifierInterface $current = $frame->getCore(); // preserve transparency + imagealphablending($modified, false); $transIndex = imagecolortransparent($current); if ($transIndex != -1) { $rgba = imagecolorsforindex($modified, $transIndex); $transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127); imagefill($modified, 0, 0, $transColor); - imagecolortransparent($modified, $transColor); } else { - imagealphablending($modified, false); imagesavealpha($modified, true); } @@ -72,6 +71,22 @@ class ResizeModifier implements ModifierInterface imagedestroy($current); + if ($transIndex != -1) { // @todo refactor because of duplication + imagecolortransparent($modified, $transIndex); + for ($y = 0; $y < $resizeTo->getHeight(); ++$y) { + for ($x = 0; $x < $resizeTo->getWidth(); ++$x) { + if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) { + imagesetpixel( + $modified, + $x, + $y, + $transIndex + ); + } + } + } + } + // set new content as recource $frame->setCore($modified); }