From 29047b132504c232a41301fa1f507e1df5708f57 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sat, 11 May 2024 20:09:36 +0200 Subject: [PATCH] Add docblock comments --- src/Geometry/Tools/RectangleResizer.php | 85 ++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/src/Geometry/Tools/RectangleResizer.php b/src/Geometry/Tools/RectangleResizer.php index ae9faa71..5462c47c 100644 --- a/src/Geometry/Tools/RectangleResizer.php +++ b/src/Geometry/Tools/RectangleResizer.php @@ -11,7 +11,10 @@ use Intervention\Image\Interfaces\SizeInterface; class RectangleResizer { /** + * @param null|int $width + * @param null|int $height * @throws GeometryException + * @return void */ public function __construct( protected ?int $width = null, @@ -31,35 +34,61 @@ class RectangleResizer } /** - * @throws GeometryException + * Static factory method to create resizer with given target size + * + * @param array $arguments + * @return RectangleResizer */ public static function to(mixed ...$arguments): self { return new self(...$arguments); } + /** + * Determine if resize has target width + * + * @return bool + */ protected function hasTargetWidth(): bool { return is_integer($this->width); } + /** + * Return target width of resizer if available + * + * @return null|int + */ protected function getTargetWidth(): ?int { return $this->hasTargetWidth() ? $this->width : null; } + /** + * Determine if resize has target height + * + * @return bool + */ protected function hasTargetHeight(): bool { return is_integer($this->height); } + /** + * Return target width of resizer if available + * + * @return null|int + */ protected function getTargetHeight(): ?int { return $this->hasTargetHeight() ? $this->height : null; } /** + * Return target size object + * * @throws GeometryException + * @return SizeInterface */ protected function getTargetSize(): SizeInterface { @@ -70,6 +99,12 @@ class RectangleResizer return new Rectangle($this->width, $this->height); } + /** + * Set target width of resizer + * + * @param int $width + * @return RectangleResizer + */ public function toWidth(int $width): self { $this->width = $width; @@ -77,6 +112,12 @@ class RectangleResizer return $this; } + /** + * Set target height of resizer + * + * @param int $height + * @return RectangleResizer + */ public function toHeight(int $height): self { $this->height = $height; @@ -84,6 +125,12 @@ class RectangleResizer return $this; } + /** + * Set target size to given size object + * + * @param SizeInterface $size + * @return RectangleResizer + */ public function toSize(SizeInterface $size): self { $this->width = $size->width(); @@ -92,6 +139,12 @@ class RectangleResizer return $this; } + /** + * Get proportinal width + * + * @param SizeInterface $size + * @return int + */ protected function getProportionalWidth(SizeInterface $size): int { if (!$this->hasTargetHeight()) { @@ -101,6 +154,12 @@ class RectangleResizer return max([1, (int) round($this->height * $size->aspectRatio())]); } + /** + * Get proportinal height + * + * @param SizeInterface $size + * @return int + */ protected function getProportionalHeight(SizeInterface $size): int { if (!$this->hasTargetWidth()) { @@ -110,6 +169,12 @@ class RectangleResizer return max([1, (int) round($this->width / $size->aspectRatio())]); } + /** + * Resize given size to target size of the resizer + * + * @param SizeInterface $size + * @return SizeInterface + */ public function resize(SizeInterface $size): SizeInterface { $resized = new Rectangle($size->width(), $size->height()); @@ -125,6 +190,12 @@ class RectangleResizer return $resized; } + /** + * Resize given size to target size of the resizer but do not exceed original size + * + * @param SizeInterface $size + * @return SizeInterface + */ public function resizeDown(SizeInterface $size): SizeInterface { $resized = new Rectangle($size->width(), $size->height()); @@ -144,6 +215,12 @@ class RectangleResizer return $resized; } + /** + * Resize given size to target size proportinally + * + * @param SizeInterface $size + * @return SizeInterface + */ public function scale(SizeInterface $size): SizeInterface { $resized = new Rectangle($size->width(), $size->height()); @@ -168,6 +245,12 @@ class RectangleResizer return $resized; } + /** + * Resize given size to target size proportinally but do not exceed original size + * + * @param SizeInterface $size + * @return SizeInterface + */ public function scaleDown(SizeInterface $size): SizeInterface { $resized = new Rectangle($size->width(), $size->height());