1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 16:50:07 +02:00

Renamed relativePosition

This commit is contained in:
Oliver Vogel
2021-11-07 16:15:30 +00:00
parent 9ac8e765c2
commit de343e1979
6 changed files with 51 additions and 15 deletions

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -368,5 +368,4 @@ class ResizerTest extends TestCase
$this->assertEquals(13, $result->getWidth());
$this->assertEquals(10, $result->getHeight());
}
}

View File

@@ -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());
}