Файл: vendor/intervention/image/src/Color.php
Строк: 345
<?php
declare(strict_types=1);
namespace InterventionImage;
use InterventionImageColorsCmykChannelsCyan;
use InterventionImageColorsCmykChannelsKey;
use InterventionImageColorsCmykChannelsMagenta;
use InterventionImageColorsCmykChannelsYellow;
use InterventionImageColorsRgbColor as RgbColor;
use InterventionImageColorsCmykColor as CmykColor;
use InterventionImageColorsHslColor as HslColor;
use InterventionImageColorsHsvColor as HsvColor;
use InterventionImageColorsOklabColor as OklabColor;
use InterventionImageColorsOklchColor as OklchColor;
use InterventionImageExceptionsDriverException;
use InterventionImageExceptionsInvalidArgumentException;
use InterventionImageInterfacesColorInterface;
use InterventionImageColorsCmykDecodersStringColorDecoder as CmykStringColorDecoder;
use InterventionImageColorsHslDecodersStringColorDecoder as HslStringColorDecoder;
use InterventionImageColorsHsvDecodersStringColorDecoder as HsvStringColorDecoder;
use InterventionImageColorsOklabDecodersStringColorDecoder as OklabStringColorDecoder;
use InterventionImageColorsOklchDecodersStringColorDecoder as OklchStringColorDecoder;
use InterventionImageColorsRgbChannelsAlpha as RgbAlpha;
use InterventionImageColorsCmykChannelsAlpha as CmykAlpha;
use InterventionImageColorsHslChannelsAlpha as HslAlpha;
use InterventionImageColorsHslChannelsHue as HslHue;
use InterventionImageColorsHslChannelsLuminance;
use InterventionImageColorsHslChannelsSaturation as HslSaturation;
use InterventionImageColorsHsvChannelsAlpha as HsvAlpha;
use InterventionImageColorsHsvChannelsHue;
use InterventionImageColorsHsvChannelsSaturation;
use InterventionImageColorsHsvChannelsValue;
use InterventionImageColorsOklabChannelsA;
use InterventionImageColorsOklabChannelsAlpha as OklabAlpha;
use InterventionImageColorsOklabChannelsB;
use InterventionImageColorsOklabChannelsLightness as OklabLightness;
use InterventionImageColorsOklchChannelsAlpha as OklchAlpha;
use InterventionImageColorsOklchChannelsChroma;
use InterventionImageColorsOklchChannelsLightness as OklchLightness;
use InterventionImageColorsRgbChannelsBlue;
use InterventionImageColorsRgbChannelsGreen;
use InterventionImageColorsRgbChannelsRed;
use InterventionImageColorsRgbDecodersHexColorDecoder as RgbHexColorDecoder;
use InterventionImageColorsRgbDecodersNamedColorDecoder;
use InterventionImageColorsRgbDecodersStringColorDecoder as RgbStringColorDecoder;
use InterventionImageExceptionsColorException;
use InterventionImageExceptionsNotSupportedException;
class Color
{
/**
* Parse color from string value.
*
* @throws InvalidArgumentException
* @throws ColorException
*/
public static function parse(string $input): ColorInterface
{
try {
$color = InputHandler::usingDecoders([
RgbStringColorDecoder::class,
CmykStringColorDecoder::class,
HsvStringColorDecoder::class,
HslStringColorDecoder::class,
OklabStringColorDecoder::class,
OklchStringColorDecoder::class,
NamedColorDecoder::class,
RgbHexColorDecoder::class,
])->handle($input);
} catch (NotSupportedException | DriverException $e) {
throw new InvalidArgumentException(
'Unable to parse RGB color from input "' . $input . '"',
previous: $e,
);
}
if (!$color instanceof ColorInterface) {
throw new ColorException('Result must be instance of ' . self::class . ', got ' . $color::class);
}
return $color;
}
/**
* Create new RGB color.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
public static function rgb(int|Red $r, int|Green $g, int|Blue $b, float|RgbAlpha $a = 1): RgbColor
{
return new RgbColor($r, $g, $b, $a);
}
/**
* Create new CMYK color.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
public static function cmyk(
int|Cyan $c,
int|Magenta $m,
int|Yellow $y,
int|Key $k,
float|CmykAlpha $a = 1,
): CmykColor {
return new CmykColor($c, $m, $y, $k, $a);
}
/**
* Create new HSL color.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
public static function hsl(int|HslHue $h, int|HslSaturation $s, int|Luminance $l, float|HslAlpha $a = 1): HslColor
{
return new HslColor($h, $s, $l, $a);
}
/**
* Create new HSV color.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
public static function hsv(int|Hue $h, int|Saturation $s, int|Value $v, float|HsvAlpha $a = 1): HsvColor
{
return new HsvColor($h, $s, $v, $a);
}
/**
* Create new OKLAB color.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
public static function oklab(
float|OklabLightness $l,
float|A $a,
float|B $b,
float|OklabAlpha $alpha = 1,
): OklabColor {
return new OklabColor($l, $a, $b, $alpha);
}
/**
* Create new OKLCH color.
*
* @throws InvalidArgumentException
* @throws DriverException
*/
public static function oklch(
float|OklchLightness $l,
float|Chroma $c,
float|Hue $h,
float|OklchAlpha $a = 1,
): OklchColor {
return new OklchColor($l, $c, $h, $a);
}
/**
* Create transparent RGB color.
*/
public static function transparent(): ColorInterface
{
// @phpstan-ignore missingType.checkedException
return new RgbColor(255, 255, 255, 0);
}
}