1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 01:51:43 +02:00

Add docblock comments

This commit is contained in:
Oliver Vogel
2024-05-11 20:09:36 +02:00
parent 193324ec88
commit 29047b1325

View File

@@ -11,7 +11,10 @@ use Intervention\Image\Interfaces\SizeInterface;
class RectangleResizer class RectangleResizer
{ {
/** /**
* @param null|int $width
* @param null|int $height
* @throws GeometryException * @throws GeometryException
* @return void
*/ */
public function __construct( public function __construct(
protected ?int $width = null, 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 public static function to(mixed ...$arguments): self
{ {
return new self(...$arguments); return new self(...$arguments);
} }
/**
* Determine if resize has target width
*
* @return bool
*/
protected function hasTargetWidth(): bool protected function hasTargetWidth(): bool
{ {
return is_integer($this->width); return is_integer($this->width);
} }
/**
* Return target width of resizer if available
*
* @return null|int
*/
protected function getTargetWidth(): ?int protected function getTargetWidth(): ?int
{ {
return $this->hasTargetWidth() ? $this->width : null; return $this->hasTargetWidth() ? $this->width : null;
} }
/**
* Determine if resize has target height
*
* @return bool
*/
protected function hasTargetHeight(): bool protected function hasTargetHeight(): bool
{ {
return is_integer($this->height); return is_integer($this->height);
} }
/**
* Return target width of resizer if available
*
* @return null|int
*/
protected function getTargetHeight(): ?int protected function getTargetHeight(): ?int
{ {
return $this->hasTargetHeight() ? $this->height : null; return $this->hasTargetHeight() ? $this->height : null;
} }
/** /**
* Return target size object
*
* @throws GeometryException * @throws GeometryException
* @return SizeInterface
*/ */
protected function getTargetSize(): SizeInterface protected function getTargetSize(): SizeInterface
{ {
@@ -70,6 +99,12 @@ class RectangleResizer
return new Rectangle($this->width, $this->height); return new Rectangle($this->width, $this->height);
} }
/**
* Set target width of resizer
*
* @param int $width
* @return RectangleResizer
*/
public function toWidth(int $width): self public function toWidth(int $width): self
{ {
$this->width = $width; $this->width = $width;
@@ -77,6 +112,12 @@ class RectangleResizer
return $this; return $this;
} }
/**
* Set target height of resizer
*
* @param int $height
* @return RectangleResizer
*/
public function toHeight(int $height): self public function toHeight(int $height): self
{ {
$this->height = $height; $this->height = $height;
@@ -84,6 +125,12 @@ class RectangleResizer
return $this; return $this;
} }
/**
* Set target size to given size object
*
* @param SizeInterface $size
* @return RectangleResizer
*/
public function toSize(SizeInterface $size): self public function toSize(SizeInterface $size): self
{ {
$this->width = $size->width(); $this->width = $size->width();
@@ -92,6 +139,12 @@ class RectangleResizer
return $this; return $this;
} }
/**
* Get proportinal width
*
* @param SizeInterface $size
* @return int
*/
protected function getProportionalWidth(SizeInterface $size): int protected function getProportionalWidth(SizeInterface $size): int
{ {
if (!$this->hasTargetHeight()) { if (!$this->hasTargetHeight()) {
@@ -101,6 +154,12 @@ class RectangleResizer
return max([1, (int) round($this->height * $size->aspectRatio())]); return max([1, (int) round($this->height * $size->aspectRatio())]);
} }
/**
* Get proportinal height
*
* @param SizeInterface $size
* @return int
*/
protected function getProportionalHeight(SizeInterface $size): int protected function getProportionalHeight(SizeInterface $size): int
{ {
if (!$this->hasTargetWidth()) { if (!$this->hasTargetWidth()) {
@@ -110,6 +169,12 @@ class RectangleResizer
return max([1, (int) round($this->width / $size->aspectRatio())]); 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 public function resize(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->width(), $size->height());
@@ -125,6 +190,12 @@ class RectangleResizer
return $resized; 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 public function resizeDown(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->width(), $size->height());
@@ -144,6 +215,12 @@ class RectangleResizer
return $resized; return $resized;
} }
/**
* Resize given size to target size proportinally
*
* @param SizeInterface $size
* @return SizeInterface
*/
public function scale(SizeInterface $size): SizeInterface public function scale(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->width(), $size->height());
@@ -168,6 +245,12 @@ class RectangleResizer
return $resized; 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 public function scaleDown(SizeInterface $size): SizeInterface
{ {
$resized = new Rectangle($size->width(), $size->height()); $resized = new Rectangle($size->width(), $size->height());