Skip to content

Commit de49c31

Browse files
authored
Merge pull request #428 from olivervogel/feature/simplify-background-manipulator
Simplify Background::class manipulator
2 parents ec195aa + bbf0976 commit de49c31

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/Manipulators/Background.php

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

77
use Intervention\Image\Interfaces\ImageInterface;
8-
use Intervention\Image\Origin;
98
use League\Glide\Manipulators\Helpers\Color;
109

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

3332
$color = (new Color($bg))->formatted();
3433

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-
);
34+
return $image->blendTransparency($color);
4135
}
4236
}

tests/Manipulators/BackgroundTest.php

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

55
namespace League\Glide\Manipulators;
66

7-
use Intervention\Image\Interfaces\DriverInterface;
87
use Intervention\Image\Interfaces\ImageInterface;
9-
use Intervention\Image\Origin;
108
use PHPUnit\Framework\TestCase;
119

1210
class BackgroundTest extends TestCase
1311
{
1412
private $manipulator;
1513

14+
public function setUp(): void
15+
{
16+
$this->manipulator = new Background();
17+
}
18+
1619
public function tearDown(): void
1720
{
1821
\Mockery::close();
@@ -26,27 +29,12 @@ public function testCreateInstance()
2629
public function testRun()
2730
{
2831
$image = \Mockery::mock(ImageInterface::class, function ($mock) {
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();
32+
$mock->shouldReceive('blendTransparency')->with('rgba(0, 0, 0, 1)')->once();
4533
});
4634

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

0 commit comments

Comments
 (0)