与えられた光の3原色、16進数の値が利用可能なカラーコードかどうか判定します。

@param	string	$rgb	光の3原色の16進数値
@return	bool	与えられた光の3原色、16進数の値がカラーコードとして使える場合はbool true、そうでない場合はbool false
357608
public static function IsHexColorCode ($rgb) {
		return (($hex_array = static::ToHexStringArray($rgb)) !== false) ? ctype_xdigit($hex_array[0]) && ctype_xdigit($hex_array[1]) && ctype_xdigit($hex_array[2]) : false;
	}
230945
public function rgbToString($rgbArray)
    {
        $result = [];
        foreach ($rgbArray as $value) {
            if (null === $value) {
                $result[] = 'null';
            } else {
                $result[] = sprintf('%02s', dechex($value));
            }
        }
        return implode($result);
    }
20874
public function setFromRGBColor(RGBColor $color)
    {
        return $this->setRed($color->getRed())
                        ->setGreen($color->getGreen())
                        ->setBlue($color->getBlue())
                        ->setAlpha($color->getAlpha());
    }
357066
protected function getRGBFromRange($r, $g, $b, $range) {
		#	get randomized rgb values on a specific range from a agiven value

		if (!$range) {
			return array($r, $g, $b);
		}

		$range = round($range / 2);
		$color = array();

		# red
		$min = $r - $range;
		$max = $r + $range;

		if ($min < 0) {
			$min = 0;
		}

		if ($max > 255) {
			$max = 255;
		}

		$color['r'] = $color[0] = rand($min, $max);

		# Green
		$min = $g - $range;
		$max = $g + $range;

		if ($min < 0) {
			$min = 0;
		}

		if ($max > 255) {
			$max = 255;
		}

		$color['g'] = $color[1] = rand($min, $max);

		# blue
		$min = $b - $range;
		$max = $b + $range;

		if ($min < 0) {
			$min = 0;
		}

		if ($max > 255) {
			$max = 255;
		}

		$color['b'] = $color[2] = rand($min, $max);

		return $color;
	}
305046
public function getRgba(){
        $rgba = $this->hexToRgb( $this->hexString );
        $rgba[] = $this->alpha;
        return $rgba;
    }
11376
public static function rgb($v1,$v2=null,$v3=null)
	{
		if(is_null($v2)){
			$rgb = $v1;
			$r = ($rgb >> 16) & 0xFF;
			$g = ($rgb >> 8) & 0xFF;
			$b = $rgb & 0xFF;
			$self = new self();
			return $self->r($r)->g($g)->b($b);
		}else{
			$r = $v1 & 0xFF;
			$g = $v2 & 0xFF;
			$b = $v3 & 0xFF;
			$self = new self();
			return $self->r($r)->g($g)->b($b);
		}
	}
729567
public function darker($shade = 0.7)
    {
        return $this->setFromArray(array(
                    max(array((integer) $this->getRed() * $shade, 0))
                    , max(array((integer) $this->getGreen() * $shade, 0))
                    , max(array((integer) $this->getBlue() * $shade, 0))
                    , $this->getAlpha()
        ));
    }
273403
public static function calculateLuminance($color)
	{
		$rgb = static::getMixedColorAsRgb($color);
		if ($rgb === false) return false;

		return 0.2126 * $rgb[0] + 0.7152 * $rgb[1] + 0.0722 * $rgb[2];
	}
871136
public function getRgba()
    {
        return sprintf('rgba(%d, %d, %d, %.2F)',
            $this->getRedValue(),
            $this->getGreenValue(),
            $this->getBlueValue(),
            $this->getAlphaValue()
        );
    }
1227862
public static function Color2Rgb( $colorDefinition )
   {

      if ( \is_array( $colorDefinition ) )
      {
         if ( \count( $colorDefinition ) > 2 && \count( $colorDefinition ) < 5 )
         {
            return $colorDefinition;
         }
         throw new ArgumentError(
            'colorDefinition',
            $colorDefinition,
            'Drawing',
            'A (a)rgb(a) array with 3-4 Elements is required!'
         );
      }

      if ( static::IsHexFormat( $colorDefinition ) )
      {
         return static::Hex2Rgb( $colorDefinition );
      }

      $uc = \strtolower( $colorDefinition );

      if ( isset( static::$ColornameRGB[ $uc ] ) )
      {
         return static::$ColornameRGB[ $uc ];
      }

      if ( false !== ( $hex = static::Rgb2Hex( $colorDefinition ) ) )
      {
         return static::Hex2Rgb( $hex );
      }

      return false;

   }
898048
public static function rgbToHsl($red, $green, $blue)
    {
        if (\min($red, $green, $blue) < 0) {
            throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0');
        }

        if (\max($red, $green, $blue) > 0xFF) {
            throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255');
        }

        $clrMin = \min($red, $green, $blue);
        $clrMax = \max($red, $green, $blue);
        $deltaMax = $clrMax - $clrMin;

        $L = ($clrMax + $clrMin) / 510;

        if (0 == $deltaMax) {
            $H = 0;
            $S = 0;
        } else {
            if (0.5 > $L) {
                $S = $deltaMax / ($clrMax + $clrMin);
            } else {
                $S = $deltaMax / (510 - $clrMax - $clrMin);
            }

            if ($clrMax === $red) {
                $H = ($green - $blue) / (6.0 * $deltaMax);

                if (0 > $H) {
                    $H += 1.0;
                }
            } elseif ($clrMax === $green) {
                $H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax);
            } else {
                $H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax);
            }
        }

        return array(
            (float) ($H * 360 % 360),
            (float) ($S * 100),
            (float) ($L * 100),
        );
    }
1244377
public static function rgb2xyz($rgb)
    {
        // Inverse sRGB Companding
        $rgb = array_map(function ($n) {
            if ($n <= 0.04045) {
                return $n / 12.92;
            }
            return pow(($n + 0.055) / 1.055, 2.4);
        }, $rgb);

        // Linear RGB to XYZ
        return array(
            0.4124564 * $rgb[0] + 0.3575761 * $rgb[1] + 0.1804375 * $rgb[2],
            0.2126729 * $rgb[0] + 0.7151522 * $rgb[1] + 0.0721750 * $rgb[2],
            0.0193339 * $rgb[0] + 0.1191920 * $rgb[1] + 0.9503041 * $rgb[2]
        );
    }
443965
static function rgbToCMYK( $rgbArray )
    {
        $cya = 1 - min( 1, max( (float)$rgbArray['r'], 0 ) );
        $mag = 1 - min( 1, max( (float)$rgbArray['g'], 0 ) );
        $yel = 1 - min( 1, max( (float)$rgbArray['b'], 0 ) );

        $min = min( $cya, $mag, $yel );
        if ( 1 - $min == 0 )
        {
            return array( 'c' => 1,
                          'm' => 1,
                          'y' => 1,
                          'k' => 0 );
        }

        return array( 'c' => ( $cya - $min ) / ( 1 - $min ),
                      'm' => ( $mag - $min ) / ( 1 - $min ),
                      'y' => ( $yel - $min ) / ( 1 - $min ),
                      'k' => $min );
    }
666649
public function transparent(String $rgb) : GD
    {
        imagecolortransparent($this->canvas, $this->allocate($rgb));

        return $this;
    }
8720
public static function rgbaValueToRgbaComponents($rgb)
    {
        self::throwExceptionIfNotRgbaValue($rgb);

        $alpha = self::rgbaValueToAlphaComponent($rgb);

        if (0 === $alpha) {
            $alpha = 0xFF;
        }

        return [
            'R' => self::rgbaValueToRedComponent($rgb),
            'G' => self::rgbaValueToGreenComponent($rgb),
            'B' => self::rgbaValueToBlueComponent($rgb),
            'A' => $alpha
        ];
    }
1261393
protected function getSRGBComponents($RGBComponents)
	    {
	        return [
	            $this->getSRGBComponent($RGBComponents[0]),
	            $this->getSRGBComponent($RGBComponents[1]),
	            $this->getSRGBComponent($RGBComponents[2])
	        ];
	    }
374621
final protected function _createImageColorAlpha(array $rgba = array())
	{
		$keys = array('r', 'g', 'b', 'a');
		$rgba = array_filter($rgba, 'is_int');
		$rgba = array_map('abs', $rgba);
		$rgba = array_pad($rgba, count($keys), 0);
		$rgba = array_slice($rgba, 0, count($keys));
		$rgba = array_combine($keys, $rgba);

		extract($rgba);

		return imagecolorallocatealpha(
			$this->_image_handle,
			min($r, 255),
			min($g, 255),
			min($b, 255),
			min($a, 127)
		);
	}