mirror of
https://github.com/Intervention/image.git
synced 2025-08-27 23:59:50 +02:00
Update GD\FitModifier.php add transparency restore to pass the tests.
This commit is contained in:
@@ -37,15 +37,14 @@ class FitModifier extends AbstractFitModifier 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);
|
||||
}
|
||||
|
||||
@@ -65,6 +64,22 @@ class FitModifier extends AbstractFitModifier implements ModifierInterface
|
||||
|
||||
imagedestroy($current);
|
||||
|
||||
if ($transIndex != -1) { // @todo refactor because of duplication
|
||||
imagecolortransparent($modified, $transIndex);
|
||||
for ($y = 0; $y < $resize->getHeight(); ++$y) {
|
||||
for ($x = 0; $x < $resize->getWidth(); ++$x) {
|
||||
if (((imagecolorat($modified, $x, $y) >> 24) & 0x7F) >= 100) {
|
||||
imagesetpixel(
|
||||
$modified,
|
||||
$x,
|
||||
$y,
|
||||
$transIndex
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set new content as resource
|
||||
$frame->setCore($modified);
|
||||
}
|
||||
|
Reference in New Issue
Block a user