From de343e197947ca0cb108f6c570b0e9ead0f1ef3d Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 7 Nov 2021 16:15:30 +0000 Subject: [PATCH] Renamed relativePosition --- src/Drivers/Gd/Modifiers/PlaceModifier.php | 2 +- .../Imagick/Modifiers/PlaceModifier.php | 2 +- src/Geometry/Resizer.php | 47 +++++++++++++++++-- src/Geometry/Size.php | 2 +- tests/Geometry/ResizerTest.php | 1 - tests/Geometry/SizeTest.php | 12 ++--- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/Drivers/Gd/Modifiers/PlaceModifier.php b/src/Drivers/Gd/Modifiers/PlaceModifier.php index c9576f2c..92f8aff1 100644 --- a/src/Drivers/Gd/Modifiers/PlaceModifier.php +++ b/src/Drivers/Gd/Modifiers/PlaceModifier.php @@ -61,6 +61,6 @@ class PlaceModifier implements ModifierInterface $image_size = $image->getSize()->align($this->position, $this->offset_x, $this->offset_y); $watermark_size = $watermark->getSize()->align($this->position); - return $image_size->relativePosition($watermark_size); + return $image_size->getRelativePositionTo($watermark_size); } } diff --git a/src/Drivers/Imagick/Modifiers/PlaceModifier.php b/src/Drivers/Imagick/Modifiers/PlaceModifier.php index e91714bc..efc8a166 100644 --- a/src/Drivers/Imagick/Modifiers/PlaceModifier.php +++ b/src/Drivers/Imagick/Modifiers/PlaceModifier.php @@ -53,6 +53,6 @@ class PlaceModifier implements ModifierInterface $image_size = $image->getSize()->align($this->position, $this->offset_x, $this->offset_y); $watermark_size = $watermark->getSize()->align($this->position); - return $image_size->relativePosition($watermark_size); + return $image_size->getRelativePositionTo($watermark_size); } } diff --git a/src/Geometry/Resizer.php b/src/Geometry/Resizer.php index 6132d58c..345afef0 100644 --- a/src/Geometry/Resizer.php +++ b/src/Geometry/Resizer.php @@ -4,6 +4,43 @@ namespace Intervention\Image\Geometry; 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 { /** @@ -31,11 +68,6 @@ class Resizer $this->target = new Size(0, 0); } - protected function copyOriginal(): SizeInterface - { - return new Size($this->original->getWidth(), $this->original->getHeight()); - } - protected function hasTargetWidth(): bool { return $this->target->getWidth() > 0; @@ -104,6 +136,11 @@ class Resizer return (int) round($this->target->getWidth() / $this->original->getAspectRatio()); } + protected function copyOriginal(): SizeInterface + { + return new Size($this->original->getWidth(), $this->original->getHeight()); + } + public function resize(): SizeInterface { $resized = $this->copyOriginal(); diff --git a/src/Geometry/Size.php b/src/Geometry/Size.php index 70aee3e1..735439f2 100644 --- a/src/Geometry/Size.php +++ b/src/Geometry/Size.php @@ -191,7 +191,7 @@ class Size implements SizeInterface * @param Size $size * @return Point */ - public function relativePosition(Size $size): Point + public function getRelativePositionTo(Size $size): Point { $x = $this->getPivot()->getX() - $size->getPivot()->getX(); $y = $this->getPivot()->getY() - $size->getPivot()->getY(); diff --git a/tests/Geometry/ResizerTest.php b/tests/Geometry/ResizerTest.php index 9c84ee91..13f2219b 100644 --- a/tests/Geometry/ResizerTest.php +++ b/tests/Geometry/ResizerTest.php @@ -368,5 +368,4 @@ class ResizerTest extends TestCase $this->assertEquals(13, $result->getWidth()); $this->assertEquals(10, $result->getHeight()); } - } diff --git a/tests/Geometry/SizeTest.php b/tests/Geometry/SizeTest.php index 37ab296a..0dc55166 100644 --- a/tests/Geometry/SizeTest.php +++ b/tests/Geometry/SizeTest.php @@ -144,13 +144,13 @@ class SizeTest extends TestCase $this->assertInstanceOf(Size::class, $result); } - public function testRelativePosition(): void + public function testgetRelativePositionTo(): void { $container = new Size(800, 600); $input = new Size(200, 100); $container->align('top-left'); $input->align('top-left'); - $pos = $container->relativePosition($input); + $pos = $container->getRelativePositionTo($input); $this->assertEquals(0, $pos->getX()); $this->assertEquals(0, $pos->getY()); @@ -158,7 +158,7 @@ class SizeTest extends TestCase $input = new Size(200, 100); $container->align('center'); $input->align('top-left'); - $pos = $container->relativePosition($input); + $pos = $container->getRelativePositionTo($input); $this->assertEquals(400, $pos->getX()); $this->assertEquals(300, $pos->getY()); @@ -166,7 +166,7 @@ class SizeTest extends TestCase $input = new Size(200, 100); $container->align('bottom-right'); $input->align('top-right'); - $pos = $container->relativePosition($input); + $pos = $container->getRelativePositionTo($input); $this->assertEquals(600, $pos->getX()); $this->assertEquals(600, $pos->getY()); @@ -174,7 +174,7 @@ class SizeTest extends TestCase $input = new Size(200, 100); $container->align('center'); $input->align('center'); - $pos = $container->relativePosition($input); + $pos = $container->getRelativePositionTo($input); $this->assertEquals(300, $pos->getX()); $this->assertEquals(250, $pos->getY()); @@ -182,7 +182,7 @@ class SizeTest extends TestCase $input = new Size(100, 100); $container->align('center'); $input->align('center'); - $pos = $container->relativePosition($input); + $pos = $container->getRelativePositionTo($input); $this->assertEquals(0, $pos->getX()); $this->assertEquals(50, $pos->getY()); }