Same filename and directory in other branches
- 8.x-2.x src/ColorCMY.php
Namespace
Drupal\color_field
Fichier
-
src/ColorCMY.php
View source
<?php
declare (strict_types=1);
namespace Drupal\color_field;
class ColorCMY extends ColorBase {
protected int $cyan;
protected int $magenta;
protected int $yellow;
public function __construct(int $cyan, int $magenta, int $yellow, float $opacity) {
$this->cyan = $cyan;
$this->magenta = $magenta;
$this->yellow = $yellow;
$this->opacity = $opacity;
}
public function getCyan() : int {
return $this->cyan;
}
public function getMagenta() : int {
return $this->magenta;
}
public function getYellow() : int {
return $this->yellow;
}
public function toString(bool $opacity = TRUE) : string {
return $this->toHex()
->toString($opacity);
}
public function toHex() : ColorHex {
return $this->toRgb()
->toHex();
}
public function toRgb() : ColorRGB {
$red = (1 - $this->cyan) * 255;
$green = (1 - $this->magenta) * 255;
$blue = (1 - $this->yellow) * 255;
return new ColorRGB($red, $green, $blue, $this->getOpacity());
}
public function toCmyk() : ColorCMYK {
$key = min($this->getCyan(), $this->getMagenta(), $this->getYellow());
$cyan = $this->cyan * (1 - $key) + $key;
$magenta = $this->magenta * (1 - $key) + $key;
$yellow = $this->yellow * (1 - $key) + $key;
return new ColorCMYK($cyan, $magenta, $yellow, $key, $this->getOpacity());
}
public function toHsl() : ColorHSL {
return $this->toRgb()
->toHsl();
}
}
Classes
| Titre |
Deprecated |
Résumé |
| ColorCMY |
|
ColorCMY represents the CMY color format. |