1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-12 08:54:03 +02:00

Revert position behaviour of resize methods

This commit is contained in:
Oliver Vogel
2023-12-07 18:37:50 +01:00
parent 2fe03aeba7
commit 3b7238f7a8
7 changed files with 9 additions and 29 deletions

View File

@@ -349,9 +349,9 @@ interface ImageInterface extends IteratorAggregate, Countable
/** /**
* Resize the boundaries of the current image to given width and height. * Resize the boundaries of the current image to given width and height.
* An anchor position can be defined to determine from what point of the * An anchor position can be defined to determine where the original image
* image the resizing is going to happen. A background color can be passed * is fixed. A background color can be passed to define the color of the
* to define the color of the new emerging areas. * new emerging areas.
* *
* @param null|int $width * @param null|int $width
* @param null|int $height * @param null|int $height

View File

@@ -25,7 +25,7 @@ class ContainModifier extends AbstractModifier
) )
->alignPivotTo( ->alignPivotTo(
$this->getResizeSize($image), $this->getResizeSize($image),
$this->position() $this->position
); );
} }
@@ -33,14 +33,4 @@ class ContainModifier extends AbstractModifier
{ {
return new Rectangle($this->width, $this->height); return new Rectangle($this->width, $this->height);
} }
protected function position(): string
{
return strtr($this->position, [
'left' => 'right',
'right' => 'left',
'top' => 'bottom',
'bottom' => 'top',
]);
}
} }

View File

@@ -16,7 +16,7 @@ class PadModifier extends ContainModifier
) )
->alignPivotTo( ->alignPivotTo(
$this->getResizeSize($image), $this->getResizeSize($image),
$this->position() $this->position
); );
} }
} }

View File

@@ -24,17 +24,7 @@ class ResizeCanvasModifier extends AbstractModifier
return (new Rectangle($width, $height)) return (new Rectangle($width, $height))
->alignPivotTo( ->alignPivotTo(
$image->size(), $image->size(),
$this->position() $this->position
); );
} }
protected function position(): string
{
return strtr($this->position, [
'left' => 'right',
'right' => 'left',
'top' => 'bottom',
'bottom' => 'top',
]);
}
} }

View File

@@ -16,7 +16,7 @@ class ResizeCanvasRelativeModifier extends ResizeCanvasModifier
return (new Rectangle($width, $height)) return (new Rectangle($width, $height))
->alignPivotTo( ->alignPivotTo(
$image->size(), $image->size(),
$this->position() $this->position
); );
} }
} }

View File

@@ -46,7 +46,7 @@ class ResizeCanvasModifierTest extends TestCase
{ {
$image = $this->createTestImage(1, 1); $image = $this->createTestImage(1, 1);
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0));
$image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'top')); $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom'));
$this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->width());
$this->assertEquals(2, $image->height()); $this->assertEquals(2, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));

View File

@@ -46,7 +46,7 @@ class ResizeCanvasModifierTest extends TestCase
{ {
$image = $this->createTestImage(1, 1); $image = $this->createTestImage(1, 1);
$this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 0, 0, 255, $image->pickColor(0, 0));
$image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'top')); $image->modify(new ResizeCanvasModifier(null, 2, 'ff0', 'bottom'));
$this->assertEquals(1, $image->width()); $this->assertEquals(1, $image->width());
$this->assertEquals(2, $image->height()); $this->assertEquals(2, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0)); $this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));