1
0
mirror of https://github.com/Intervention/image.git synced 2025-07-31 11:00:12 +02:00

Update GD\ResizeModifier.php add transparency restore to pass the tests.

This commit is contained in:
Sergey Kudashev
2022-03-24 01:53:37 +03:00
parent b626022fa7
commit adffed3881

View File

@@ -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);
}