mirror of
https://github.com/Intervention/image.git
synced 2025-08-20 04:31:24 +02:00
Add doc blocks
This commit is contained in:
@@ -9,31 +9,71 @@ class Red implements ColorChannelInterface
|
|||||||
{
|
{
|
||||||
protected int $value;
|
protected int $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and validate new instance
|
||||||
|
*
|
||||||
|
* @param int $value
|
||||||
|
*/
|
||||||
public function __construct(int $value)
|
public function __construct(int $value)
|
||||||
{
|
{
|
||||||
$this->value = $this->validate($value);
|
$this->value = $this->validate($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias of value()
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function toInt(): int
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::value()
|
||||||
|
*/
|
||||||
public function value(): int
|
public function value(): int
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::normalize()
|
||||||
|
*/
|
||||||
public function normalize($precision = 32): float
|
public function normalize($precision = 32): float
|
||||||
{
|
{
|
||||||
return round($this->value() / $this->max(), $precision);
|
return round($this->value() / $this->max(), $precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::min()
|
||||||
|
*/
|
||||||
public function min(): int
|
public function min(): int
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::max()
|
||||||
|
*/
|
||||||
public function max(): int
|
public function max(): int
|
||||||
{
|
{
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::validate()
|
||||||
|
*/
|
||||||
public function validate(mixed $value): mixed
|
public function validate(mixed $value): mixed
|
||||||
{
|
{
|
||||||
if ($value < $this->min() || $value > $this->max()) {
|
if ($value < $this->min() || $value > $this->max()) {
|
||||||
@@ -43,11 +83,21 @@ class Red implements ColorChannelInterface
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::toString()
|
||||||
|
*/
|
||||||
public function toString(): string
|
public function toString(): string
|
||||||
{
|
{
|
||||||
return (string) $this->value();
|
return (string) $this->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
|
* @see ColorChannelInterface::__toString()
|
||||||
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return $this->toString();
|
return $this->toString();
|
||||||
|
@@ -4,11 +4,53 @@ namespace Intervention\Image\Interfaces;
|
|||||||
|
|
||||||
interface ColorChannelInterface
|
interface ColorChannelInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Return color channels integer value
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function value(): int;
|
public function value(): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the channels value normalized to a float value form 0 to 1 by its range
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
public function normalize(int $precision = 32): float;
|
public function normalize(int $precision = 32): float;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throw exception if the given value is not applicable for channel
|
||||||
|
* otherwise the value is returned unchanged.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function validate(mixed $value): mixed;
|
public function validate(mixed $value): mixed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the the minimal possible value of the color channel
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function min(): int;
|
public function min(): int;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the the maximal possible value of the color channel
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public function max(): int;
|
public function max(): int;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast color channel's value to string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function toString(): string;
|
public function toString(): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast color channel's value to string
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function __toString(): string;
|
public function __toString(): string;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user