mirror of
https://github.com/Intervention/image.git
synced 2025-08-29 16:50:07 +02:00
Renamed relativePosition
This commit is contained in:
@@ -61,6 +61,6 @@ class PlaceModifier implements ModifierInterface
|
|||||||
$image_size = $image->getSize()->align($this->position, $this->offset_x, $this->offset_y);
|
$image_size = $image->getSize()->align($this->position, $this->offset_x, $this->offset_y);
|
||||||
$watermark_size = $watermark->getSize()->align($this->position);
|
$watermark_size = $watermark->getSize()->align($this->position);
|
||||||
|
|
||||||
return $image_size->relativePosition($watermark_size);
|
return $image_size->getRelativePositionTo($watermark_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,6 @@ class PlaceModifier implements ModifierInterface
|
|||||||
$image_size = $image->getSize()->align($this->position, $this->offset_x, $this->offset_y);
|
$image_size = $image->getSize()->align($this->position, $this->offset_x, $this->offset_y);
|
||||||
$watermark_size = $watermark->getSize()->align($this->position);
|
$watermark_size = $watermark->getSize()->align($this->position);
|
||||||
|
|
||||||
return $image_size->relativePosition($watermark_size);
|
return $image_size->getRelativePositionTo($watermark_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,43 @@ namespace Intervention\Image\Geometry;
|
|||||||
|
|
||||||
use Intervention\Image\Interfaces\SizeInterface;
|
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
|
class Resizer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -31,11 +68,6 @@ class Resizer
|
|||||||
$this->target = new Size(0, 0);
|
$this->target = new Size(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function copyOriginal(): SizeInterface
|
|
||||||
{
|
|
||||||
return new Size($this->original->getWidth(), $this->original->getHeight());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function hasTargetWidth(): bool
|
protected function hasTargetWidth(): bool
|
||||||
{
|
{
|
||||||
return $this->target->getWidth() > 0;
|
return $this->target->getWidth() > 0;
|
||||||
@@ -104,6 +136,11 @@ class Resizer
|
|||||||
return (int) round($this->target->getWidth() / $this->original->getAspectRatio());
|
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
|
public function resize(): SizeInterface
|
||||||
{
|
{
|
||||||
$resized = $this->copyOriginal();
|
$resized = $this->copyOriginal();
|
||||||
|
@@ -191,7 +191,7 @@ class Size implements SizeInterface
|
|||||||
* @param Size $size
|
* @param Size $size
|
||||||
* @return Point
|
* @return Point
|
||||||
*/
|
*/
|
||||||
public function relativePosition(Size $size): Point
|
public function getRelativePositionTo(Size $size): Point
|
||||||
{
|
{
|
||||||
$x = $this->getPivot()->getX() - $size->getPivot()->getX();
|
$x = $this->getPivot()->getX() - $size->getPivot()->getX();
|
||||||
$y = $this->getPivot()->getY() - $size->getPivot()->getY();
|
$y = $this->getPivot()->getY() - $size->getPivot()->getY();
|
||||||
|
@@ -368,5 +368,4 @@ class ResizerTest extends TestCase
|
|||||||
$this->assertEquals(13, $result->getWidth());
|
$this->assertEquals(13, $result->getWidth());
|
||||||
$this->assertEquals(10, $result->getHeight());
|
$this->assertEquals(10, $result->getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -144,13 +144,13 @@ class SizeTest extends TestCase
|
|||||||
$this->assertInstanceOf(Size::class, $result);
|
$this->assertInstanceOf(Size::class, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRelativePosition(): void
|
public function testgetRelativePositionTo(): void
|
||||||
{
|
{
|
||||||
$container = new Size(800, 600);
|
$container = new Size(800, 600);
|
||||||
$input = new Size(200, 100);
|
$input = new Size(200, 100);
|
||||||
$container->align('top-left');
|
$container->align('top-left');
|
||||||
$input->align('top-left');
|
$input->align('top-left');
|
||||||
$pos = $container->relativePosition($input);
|
$pos = $container->getRelativePositionTo($input);
|
||||||
$this->assertEquals(0, $pos->getX());
|
$this->assertEquals(0, $pos->getX());
|
||||||
$this->assertEquals(0, $pos->getY());
|
$this->assertEquals(0, $pos->getY());
|
||||||
|
|
||||||
@@ -158,7 +158,7 @@ class SizeTest extends TestCase
|
|||||||
$input = new Size(200, 100);
|
$input = new Size(200, 100);
|
||||||
$container->align('center');
|
$container->align('center');
|
||||||
$input->align('top-left');
|
$input->align('top-left');
|
||||||
$pos = $container->relativePosition($input);
|
$pos = $container->getRelativePositionTo($input);
|
||||||
$this->assertEquals(400, $pos->getX());
|
$this->assertEquals(400, $pos->getX());
|
||||||
$this->assertEquals(300, $pos->getY());
|
$this->assertEquals(300, $pos->getY());
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ class SizeTest extends TestCase
|
|||||||
$input = new Size(200, 100);
|
$input = new Size(200, 100);
|
||||||
$container->align('bottom-right');
|
$container->align('bottom-right');
|
||||||
$input->align('top-right');
|
$input->align('top-right');
|
||||||
$pos = $container->relativePosition($input);
|
$pos = $container->getRelativePositionTo($input);
|
||||||
$this->assertEquals(600, $pos->getX());
|
$this->assertEquals(600, $pos->getX());
|
||||||
$this->assertEquals(600, $pos->getY());
|
$this->assertEquals(600, $pos->getY());
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ class SizeTest extends TestCase
|
|||||||
$input = new Size(200, 100);
|
$input = new Size(200, 100);
|
||||||
$container->align('center');
|
$container->align('center');
|
||||||
$input->align('center');
|
$input->align('center');
|
||||||
$pos = $container->relativePosition($input);
|
$pos = $container->getRelativePositionTo($input);
|
||||||
$this->assertEquals(300, $pos->getX());
|
$this->assertEquals(300, $pos->getX());
|
||||||
$this->assertEquals(250, $pos->getY());
|
$this->assertEquals(250, $pos->getY());
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ class SizeTest extends TestCase
|
|||||||
$input = new Size(100, 100);
|
$input = new Size(100, 100);
|
||||||
$container->align('center');
|
$container->align('center');
|
||||||
$input->align('center');
|
$input->align('center');
|
||||||
$pos = $container->relativePosition($input);
|
$pos = $container->getRelativePositionTo($input);
|
||||||
$this->assertEquals(0, $pos->getX());
|
$this->assertEquals(0, $pos->getX());
|
||||||
$this->assertEquals(50, $pos->getY());
|
$this->assertEquals(50, $pos->getY());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user