Вход Регистрация
Файл: vendor/intervention/image/src/Colors/Hsl/Color.php
Строк: 182
<?php

declare(strict_types=1);

namespace 
InterventionImageColorsHsl;

use 
InterventionImageColorsAbstractColor;
use 
InterventionImageColorsHslChannelsHue;
use 
InterventionImageColorsHslChannelsLuminance;
use 
InterventionImageColorsHslChannelsSaturation;
use 
InterventionImageColorsRgbColorspace as RgbColorspace;
use 
InterventionImageInputHandler;
use 
InterventionImageInterfacesColorChannelInterface;
use 
InterventionImageInterfacesColorInterface;
use 
InterventionImageInterfacesColorspaceInterface;

class 
Color extends AbstractColor
{
    
/**
     * Create new color object
     *
     * @param int $h
     * @param int $s
     * @param int $l
     * @return void
     */
    
public function __construct(int $hint $sint $l)
    {
        
/** @throws void */
        
$this->channels = [
            new 
Hue($h),
            new 
Saturation($s),
            new 
Luminance($l),
        ];
    }

    
/**
     * {@inheritdoc}
     *
     * @see ColorInterface::colorspace()
     */
    
public function colorspace(): ColorspaceInterface
    
{
        return new 
Colorspace();
    }

    
/**
     * {@inheritdoc}
     *
     * @see ColorInterface::create()
     */
    
public static function create(mixed $input): ColorInterface
    
{
        return 
InputHandler::withDecoders([
            
DecodersStringColorDecoder::class,
        ])->
handle($input);
    }

    
/**
     * Return the Hue channel
     *
     * @return ColorChannelInterface
     */
    
public function hue(): ColorChannelInterface
    
{
        
/** @throws void */
        
return $this->channel(Hue::class);
    }

    
/**
     * Return the Saturation channel
     *
     * @return ColorChannelInterface
     */
    
public function saturation(): ColorChannelInterface
    
{
        
/** @throws void */
        
return $this->channel(Saturation::class);
    }

    
/**
     * Return the Luminance channel
     *
     * @return ColorChannelInterface
     */
    
public function luminance(): ColorChannelInterface
    
{
        
/** @throws void */
        
return $this->channel(Luminance::class);
    }

    public function 
toHex(string $prefix ''): string
    
{
        return 
$this->convertTo(RgbColorspace::class)->toHex($prefix);
    }

    
/**
     * {@inheritdoc}
     *
     * @see ColorInterface::toString()
     */
    
public function toString(): string
    
{
        return 
sprintf(
            
'hsl(%d, %d%%, %d%%)',
            
$this->hue()->value(),
            
$this->saturation()->value(),
            
$this->luminance()->value()
        );
    }

    
/**
     * {@inheritdoc}
     *
     * @see ColorInterface::isGreyscale()
     */
    
public function isGreyscale(): bool
    
{
        return 
$this->saturation()->value() == 0;
    }

    
/**
     * {@inheritdoc}
     *
     * @see ColorInterface::isTransparent()
     */
    
public function isTransparent(): bool
    
{
        return 
false;
    }

    
/**
     * {@inheritdoc}
     *
     * @see ColorInterface::isClear()
     */
    
public function isClear(): bool
    
{
        return 
false;
    }
}
Онлайн: 1
Реклама