Skip to content

Commit 7ef6dad

Browse files
authored
Merge pull request #431 from thephpleague/revert-428
Revert "Simplify Background::class manipulator"
2 parents 488d33b + af721cd commit 7ef6dad

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/Manipulators/Background.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace League\Glide\Manipulators;
66

77
use Intervention\Image\Interfaces\ImageInterface;
8+
use Intervention\Image\Origin;
89
use League\Glide\Manipulators\Helpers\Color;
910

1011
class Background extends BaseManipulator
@@ -31,6 +32,11 @@ public function run(ImageInterface $image): ImageInterface
3132

3233
$color = (new Color($bg))->formatted();
3334

34-
return $image->blendTransparency($color);
35+
return $image->driver()->createImage($image->width(), $image->height())
36+
->fill($color)
37+
->place($image, 'top-left', 0, 0)
38+
->setOrigin(
39+
new Origin($image->origin()->mediaType())
40+
);
3541
}
3642
}

tests/Manipulators/BackgroundTest.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44

55
namespace League\Glide\Manipulators;
66

7+
use Intervention\Image\Interfaces\DriverInterface;
78
use Intervention\Image\Interfaces\ImageInterface;
9+
use Intervention\Image\Origin;
810
use PHPUnit\Framework\TestCase;
911

1012
class BackgroundTest extends TestCase
1113
{
1214
private $manipulator;
1315

14-
public function setUp(): void
15-
{
16-
$this->manipulator = new Background();
17-
}
18-
1916
public function tearDown(): void
2017
{
2118
\Mockery::close();
@@ -29,12 +26,27 @@ public function testCreateInstance()
2926
public function testRun()
3027
{
3128
$image = \Mockery::mock(ImageInterface::class, function ($mock) {
32-
$mock->shouldReceive('blendTransparency')->with('rgba(0, 0, 0, 1)')->once();
29+
$originMock = \Mockery::mock(Origin::class, ['mediaType' => 'image/jpeg']);
30+
31+
$mock->shouldReceive('width')->andReturn(100)->once();
32+
$mock->shouldReceive('height')->andReturn(100)->once();
33+
$mock->shouldReceive('origin')->andReturn($originMock)->once();
34+
35+
$mock->shouldReceive('driver')->andReturn(\Mockery::mock(DriverInterface::class, function ($mock) {
36+
$mock->shouldReceive('createImage')->with(100, 100)->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) {
37+
$mock->shouldReceive('fill')->with('rgba(0, 0, 0, 1)')->andReturn(\Mockery::mock(ImageInterface::class, function ($mock) {
38+
$mock->shouldReceive('setOrigin')->withArgs(function ($arg1) {
39+
return $arg1 instanceof Origin;
40+
})->andReturn($mock)->once();
41+
$mock->shouldReceive('place')->andReturn($mock)->once();
42+
}))->once();
43+
}))->once();
44+
}))->once();
3345
});
3446

35-
$this->assertInstanceOf(
36-
ImageInterface::class,
37-
$this->manipulator->setParams(['bg' => 'black'])->run($image)
38-
);
47+
$border = new Background();
48+
49+
$this->assertInstanceOf(ImageInterface::class, $border->run($image));
50+
$this->assertInstanceOf(ImageInterface::class, $border->setParams(['bg' => 'black'])->run($image));
3951
}
4052
}

0 commit comments

Comments
 (0)