Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Dec 7, 2023
1 parent 59a4353 commit 2fe03ae
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 10 deletions.
7 changes: 6 additions & 1 deletion src/Image.php
Expand Up @@ -537,11 +537,16 @@ public function resizeCanvas(
return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position));
}

/**
* {@inheritdoc}
*
* @see ImageInterface::resizeCanvasRelative()
*/
public function resizeCanvasRelative(
?int $width = null,
?int $height = null,
mixed $background = 'ffffff',
string $position = 'center',
string $position = 'center'
): ImageInterface {
return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Interfaces/ImageInterface.php
Expand Up @@ -403,7 +403,7 @@ public function pad(
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center',
string $position = 'center'
): ImageInterface;

/**
Expand All @@ -420,7 +420,7 @@ public function contain(
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center',
string $position = 'center'
): ImageInterface;

/**
Expand All @@ -440,7 +440,7 @@ public function crop(
int $height,
int $offset_x = 0,
int $offset_y = 0,
string $position = 'top-left',
string $position = 'top-left'
): ImageInterface;

/**
Expand Down
20 changes: 18 additions & 2 deletions src/Modifiers/ContainModifier.php
Expand Up @@ -19,12 +19,28 @@ public function __construct(
public function getCropSize(ImageInterface $image): SizeInterface
{
return $image->size()
->contain($this->width, $this->height)
->alignPivotTo($this->getResizeSize($image), $this->position);
->contain(
$this->width,
$this->height
)
->alignPivotTo(
$this->getResizeSize($image),
$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',
]);
}
}
10 changes: 8 additions & 2 deletions src/Modifiers/PadModifier.php
Expand Up @@ -10,7 +10,13 @@ class PadModifier extends ContainModifier
public function getCropSize(ImageInterface $image): SizeInterface
{
return $image->size()
->containMax($this->width, $this->height)
->alignPivotTo($this->getResizeSize($image), $this->position);
->containMax(
$this->width,
$this->height
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position()
);
}
}
5 changes: 4 additions & 1 deletion src/Modifiers/ResizeCanvasModifier.php
Expand Up @@ -22,7 +22,10 @@ public function cropSize(ImageInterface $image): SizeInterface
$height = is_null($this->height) ? $image->height() : $this->height;

return (new Rectangle($width, $height))
->alignPivotTo($image->size(), $this->position());
->alignPivotTo(
$image->size(),
$this->position()
);
}

protected function position(): string
Expand Down
5 changes: 4 additions & 1 deletion src/Modifiers/ResizeCanvasRelativeModifier.php
Expand Up @@ -14,6 +14,9 @@ public function cropSize(ImageInterface $image): SizeInterface
$height = is_null($this->height) ? $image->height() : $image->height() + $this->height;

return (new Rectangle($width, $height))
->alignPivotTo($image->size(), $this->position());
->alignPivotTo(
$image->size(),
$this->position()
);
}
}

0 comments on commit 2fe03ae

Please sign in to comment.