diff --git a/src/Geometry/Resizer.php b/src/Geometry/Resizer.php index e704314b..5b4c7277 100644 --- a/src/Geometry/Resizer.php +++ b/src/Geometry/Resizer.php @@ -5,43 +5,6 @@ namespace Intervention\Image\Geometry; use Intervention\Image\Geometry\Size; use Intervention\Image\Interfaces\SizeInterface; -/* - -modes: fill, contain, cover -resize($width, $height, $mode, $only_reduce) -resize(function($size) { - $size->width(300); - $size->contain(); - $size->reduce(); -}); - -- resize -- resizeDown -- scale -- scaleDown -- contain -- containDown -- cover -- coverDown - -- resize -- resizeDown -- scale -- scaleDown -- fit(contain|cover) -- fitDown(contain|cover) - -- resize -- resizeDown -- scale -- scaleDown -- fit -- fitDown -- pad -- padDown - - */ - class Resizer { /** diff --git a/src/Geometry/Size.php b/src/Geometry/Size.php index 3f4e76a4..05aa9ad1 100644 --- a/src/Geometry/Size.php +++ b/src/Geometry/Size.php @@ -29,6 +29,20 @@ class Size implements SizeInterface return $this->height; } + public function setWidth(int $width): SizeInterface + { + $this->width = $width; + + return $this; + } + + public function setHeight(int $height): SizeInterface + { + $this->height = $height; + + return $this; + } + /** * Get current pivot point * @@ -46,20 +60,6 @@ class Size implements SizeInterface return $this; } - public function setWidth(int $width): SizeInterface - { - $this->width = $width; - - return $this; - } - - public function setHeight(int $height): SizeInterface - { - $this->height = $height; - - return $this; - } - public function getAspectRatio(): float { return $this->width / $this->height; diff --git a/tests/Geometry/PointTest.php b/tests/Geometry/PointTest.php index f2d15b2e..a1d6423d 100644 --- a/tests/Geometry/PointTest.php +++ b/tests/Geometry/PointTest.php @@ -23,7 +23,7 @@ class PointTest extends TestCase $this->assertEquals(50, $point->getY()); } - public function testSetX() + public function testGetSetX() { $point = new Point(0, 0); $point->setX(100); @@ -31,7 +31,7 @@ class PointTest extends TestCase $this->assertEquals(0, $point->getY()); } - public function testSetY() + public function testGetSetY() { $point = new Point(0, 0); $point->setY(100); diff --git a/tests/Geometry/ResizerTest.php b/tests/Geometry/ResizerTest.php index 70ec340a..fb7b37e6 100644 --- a/tests/Geometry/ResizerTest.php +++ b/tests/Geometry/ResizerTest.php @@ -9,6 +9,30 @@ use PHPUnit\Framework\TestCase; class ResizerTest extends TestCase { + public function testMake(): void + { + $result = Resizer::make(); + $this->assertInstanceOf(Resizer::class, $result); + } + + public function testSetTargetWidth(): void + { + $resizer = new Resizer(); + $result = $resizer->width(100); + $this->assertInstanceOf(Resizer::class, $result); + $result = $resizer->toWidth(100); + $this->assertInstanceOf(Resizer::class, $result); + } + + public function testSetTargetHeight(): void + { + $resizer = new Resizer(); + $result = $resizer->height(100); + $this->assertInstanceOf(Resizer::class, $result); + $result = $resizer->toHeight(100); + $this->assertInstanceOf(Resizer::class, $result); + } + public function testSetTargetSizeByArray() { $size = new Size(300, 200); @@ -64,6 +88,16 @@ class ResizerTest extends TestCase $this->assertEquals(100, $resizer->resize($size)->getHeight()); } + public function testToSize(): void + { + $size = new Size(300, 200); + $resizer = new Resizer(); + $resizer = $resizer->toSize(new Size(200, 100)); + $this->assertInstanceOf(Resizer::class, $resizer); + $this->assertEquals(200, $resizer->resize($size)->getWidth()); + $this->assertEquals(100, $resizer->resize($size)->getHeight()); + } + public function testResize() { $size = new Size(300, 200); diff --git a/tests/Geometry/SizeTest.php b/tests/Geometry/SizeTest.php index 024bdf52..0e0622a0 100644 --- a/tests/Geometry/SizeTest.php +++ b/tests/Geometry/SizeTest.php @@ -37,16 +37,33 @@ class SizeTest extends TestCase $this->assertFalse($size3 == $size4); } - public function testGetWidth() + public function testSetGetWidth() { $size = new Size(800, 600); $this->assertEquals(800, $size->getWidth()); + $result = $size->setWidth(30); + $this->assertEquals(30, $size->getWidth()); + $this->assertInstanceOf(Size::class, $result); } - public function testGetHeight() + public function testSetGetHeight() { $size = new Size(800, 600); $this->assertEquals(600, $size->getHeight()); + $result = $size->setHeight(30); + $this->assertEquals(30, $size->getHeight()); + $this->assertInstanceOf(Size::class, $result); + } + + public function testSetGetPivot(): void + { + $size = new Size(800, 600); + $pivot = $size->getPivot(); + $this->assertInstanceOf(Point::class, $pivot); + $this->assertEquals(0, $pivot->getX()); + $result = $size->setPivot(new Point(10, 0)); + $this->assertInstanceOf(Size::class, $result); + $this->assertEquals(10, $size->getPivot()->getX()); } public function testGetAspectRatio()