Skip to content

Commit

Permalink
Revert position behaviour of resize methods
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 7, 2023
1 parent 2fe03ae commit 3b7238f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/Interfaces/ImageInterface.php
Expand Up @@ -349,9 +349,9 @@ public function coverDown(int $width, int $height, string $position = 'center'):

/**
* 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
* image the resizing is going to happen. A background color can be passed
* to define the color of the new emerging areas.
* An anchor position can be defined to determine where the original image
* is fixed. A background color can be passed to define the color of the
* new emerging areas.
*
* @param null|int $width
* @param null|int $height
Expand Down
12 changes: 1 addition & 11 deletions src/Modifiers/ContainModifier.php
Expand Up @@ -25,22 +25,12 @@ public function getCropSize(ImageInterface $image): SizeInterface
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position()
$this->position
);
}

public function getResizeSize(ImageInterface $image): SizeInterface
{
return new Rectangle($this->width, $this->height);
}

protected function position(): string
{
return strtr($this->position, [
'left' => 'right',
'right' => 'left',
'top' => 'bottom',
'bottom' => 'top',
]);
}
}
2 changes: 1 addition & 1 deletion src/Modifiers/PadModifier.php
Expand Up @@ -16,7 +16,7 @@ public function getCropSize(ImageInterface $image): SizeInterface
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position()
$this->position
);
}
}
12 changes: 1 addition & 11 deletions src/Modifiers/ResizeCanvasModifier.php
Expand Up @@ -24,17 +24,7 @@ public function cropSize(ImageInterface $image): SizeInterface
return (new Rectangle($width, $height))
->alignPivotTo(
$image->size(),
$this->position()
$this->position
);
}

protected function position(): string
{
return strtr($this->position, [
'left' => 'right',
'right' => 'left',
'top' => 'bottom',
'bottom' => 'top',
]);
}
}
2 changes: 1 addition & 1 deletion src/Modifiers/ResizeCanvasRelativeModifier.php
Expand Up @@ -16,7 +16,7 @@ public function cropSize(ImageInterface $image): SizeInterface
return (new Rectangle($width, $height))
->alignPivotTo(
$image->size(),
$this->position()
$this->position
);
}
}
2 changes: 1 addition & 1 deletion tests/Drivers/Gd/Modifiers/ResizeCanvasModifierTest.php
Expand Up @@ -46,7 +46,7 @@ public function testModifyEdge(): void
{
$image = $this->createTestImage(1, 1);
$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(2, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
Expand Down
Expand Up @@ -46,7 +46,7 @@ public function testModifyEdge(): void
{
$image = $this->createTestImage(1, 1);
$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(2, $image->height());
$this->assertColor(255, 255, 0, 255, $image->pickColor(0, 0));
Expand Down

0 comments on commit 3b7238f

Please sign in to comment.