mirror of
https://github.com/Intervention/image.git
synced 2025-08-06 13:56:30 +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();
|
$current = $frame->getCore();
|
||||||
|
|
||||||
// preserve transparency
|
// preserve transparency
|
||||||
|
imagealphablending($modified, false);
|
||||||
$transIndex = imagecolortransparent($current);
|
$transIndex = imagecolortransparent($current);
|
||||||
|
|
||||||
if ($transIndex != -1) {
|
if ($transIndex != -1) {
|
||||||
$rgba = imagecolorsforindex($modified, $transIndex);
|
$rgba = imagecolorsforindex($modified, $transIndex);
|
||||||
$transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
|
$transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
|
||||||
imagefill($modified, 0, 0, $transColor);
|
imagefill($modified, 0, 0, $transColor);
|
||||||
imagecolortransparent($modified, $transColor);
|
|
||||||
} else {
|
} else {
|
||||||
imagealphablending($modified, false);
|
|
||||||
imagesavealpha($modified, true);
|
imagesavealpha($modified, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +71,22 @@ class ResizeModifier implements ModifierInterface
|
|||||||
|
|
||||||
imagedestroy($current);
|
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
|
// set new content as recource
|
||||||
$frame->setCore($modified);
|
$frame->setCore($modified);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user