mirror of
https://github.com/Intervention/image.git
synced 2025-08-01 11:30:16 +02:00
Update GD\ResizeModifier.php add transparency restore to pass the tests.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user