Accueil > > > CLASS DE COULEUR
CLASS DE COULEUR
Information sur la source
Description
Suite à un commentaire interessant de Coucou747 sur la source "PHP5-CLASSE-CONVERSION-RGB-HEXA", j'ai voulu créer une Classe qui correspond à ses critères. Il suffit juste d'instancier la Class "Color" avec (au choix) le nom d'une couleur, son code hexadécimal ou son code RGB et on obtient le reste des informations concernant la couleur. La Class abstraite "ConvertColor" peut être également utilisée pour la conversion Hexadécimal en RGB (ou inversement). Je vous conseille d'ailleurs d'utilisé "is_Hex" ou "is_RGB" avant toute conversion à moins biensur que vous êtes sûr des données que vous utilisez.
Source
- <?php
-
- abstract class ConvertColor {
- // Constante de Class "__COLORSFILE__" : Contient le chemin du fichier Colors.
- const __COLORSFILE__ = 'Colors.xml';
- // Propriété privée et statique "$oXML" : Contient l'objet SimpleXML du fichier Colors.
- private static $oXml;
-
- // Méthode protégée" __construct" : Lit le fichier Colors.
- protected function __construct() {
- if (!isset($oXML)) {
- if (!is_file(self::__COLORSFILE__)) throw new Exception('Le fichier "'.self::__COLORSFILE.'" est manquant.');
- clearstatcache();
- self::$oXml = simplexml_load_file(self::__COLORSFILE__);
- if (self::$oXml === FALSE) throw new Exception('Erreur dans le fichier "'.self::__COLORSFILE.'".');
- }
- }
-
- // Méthode protégée "AddColorHex" : Retourne l'addition de la chaîne Hex du paramètre "$sHex" et de la chaîne Hex du paramètre "$sHex2".
- protected function AddColorHex($sHex1, $sHex2) {
- $aFinal[0] = hexdec(substr($sHex1, 0, 2))+hexdec(substr($sHex2, 0, 2));
- if ($aFinal[0] > 255) $aFinal[0] = 255;
- $aFinal[1] = hexdec(substr($sHex1, 2, 2))+hexdec(substr($sHex2, 2, 2));
- if ($aFinal[1] > 255) $aFinal[1] = 255;
- $aFinal[2] = hexdec(substr($sHex1, 4, 2))+hexdec(substr($sHex2, 4, 2));
- if ($aFinal[2] > 255) $aFinal[2] = 255;
- return sprintf('%02X%02X%02X', $aFinal[0], $aFinal[1], $aFinal[2]);
- }
-
- // Méthode protégée "AddColorRGB" : Retourne l'addition de la chaîne RGB du paramètre "$sRGB1" et de la chaîne RGB du paramètre "$sRGB2".
- protected function AddColorRGB($sRGB1, $sRGB2) {
- $aTemp = array(explode(',', $sRGB1), explode(',', $sRGB2));
- $aFinal = array($aTemp[0][0]+$aTemp[1][0], $aTemp[0][1]+$aTemp[1][1], $aTemp[0][2]+$aTemp[1][2]);
- if ($aFinal[0] > 255) $aFinal[0] = 255;
- if ($aFinal[1] > 255) $aFinal[1] = 255;
- if ($aFinal[2] > 255) $aFinal[2] = 255;
- return $aFinal[0].','.$aFinal[1].','.$aFinal[2];
- }
-
- // Méthode protégée "Hex3toHex6" : Retourne une chaîne hexadécimale de 6 nombres suivant la chaîne hexadécimale du paramètre "$sHex".
- protected function Hex3toHex6($sHex) {
- if (strlen($sHex) === 3) {
- $sHex = substr_replace($sHex, '0', 0, 0);
- $sHex = substr_replace($sHex, '0', 2, 0);
- $sHex = substr_replace($sHex, '0', 4, 0);
- }
- return $sHex;
- }
-
- // Méthode protégée "HextoHSL" : Retourne la chaîne HSL suivant la chaîne hexadécimale du paramètre "$sHex".
- protected function HextoHSL($sHex) {
- $aTemp = array(hexdec(substr($sHex, 0, 2)), hexdec(substr($sHex, 2, 2)), hexdec(substr($sHex, 4, 2)));
- $iMax = max($aTemp[0], $aTemp[1], $aTemp[2]);
- $iMin = min($aTemp[0], $aTemp[1], $aTemp[2]);
- $iDelta = $iMax-$iMin;
- if ($iDelta === 0) $iH = 160;
- elseif ($iMax === $aTemp[0]) {
- if ($aTemp[1] >= $aTemp[2]) $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta));
- else $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta)+360);
- }
- elseif ($iMax === $aTemp[1]) $iH = round(60*(($aTemp[2]-$aTemp[0])/$iDelta)+120);
- else $iH = round(60*(($aTemp[0]-$aTemp[1])/$iDelta)+240);
- $iL = round(240/255*$iMax);
- if ($iL === 0 OR $iMax === $iMin) $iS = 0;
- else $iS = round(240*($iDelta/$iMax));
- return $iH.','.$iS.','.$iL;
- }
-
- // Méthode protégée "HextoName" : Retourne le nom d'une couleur suivant la chaîne hexadécimale du paramètre "$sHex", sinon retourne NULL si le nom de la couleur n'est pas trouvé dans le fichier Colors.
- protected function HextoName($sHex) {
- $aXpath = self::$oXml->xpath('//color[@hex="'.strtoupper($sHex).'"]');
- if (end($aXpath) === FALSE) return NULL;
- return (string) end($aXpath)->attributes()->name;
- }
-
- // Méthode protégée "HextoRGB" : Retourne une chaîne RGB suivant la chaîne hexadécimale du paramètre "$sHex".
- protected function HextoRGB($sHex) {
- return hexdec(substr($sHex, 0, 2)).','.hexdec(substr($sHex, 2, 2)).','.hexdec(substr($sHex, 4, 2));
- }
-
- // Méthode protégée "HSL240toHSLother" : Retourne la chaîne HSL du paramètre "$sHSL" convertie pour avoir comme valeur maximale le nombre "$iMax".
- protected function HSL240toHSLother($sHSL, $iMax) {
- $aTemp = explode(',', $sHSL);
- return $aTemp[0].','.round($aTemp[1]/240*$iMax).','.round($aTemp[2]/240*$iMax);
- }
-
- // Méthode protégée "HSLChangeHue" : Retourne la chaîne HSL du paramètre "$sHSL" en ayant modifier la teite suivant le nombre du paramètre "$iHue".
- protected function HSLChangeHue($sHSL, $iHue) {
- $aTemp = explode(',', $sHSL);
- $aTemp[0] = ($aTemp[0]+$iHue)%360;
- if ($aTemp[0] < 0) return (360+$aTemp[0]).','.$aTemp[1].','.$aTemp[2];
- return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégée "HSLChangeLuminosity" : Retourne la chaîne HSL du paramètre "$sHSL" en ayant modifier la luminosité suivant le nombre du paramètre "$iLuminosity".
- protected function HSLChangeLuminosity($sHSL, $iLuminosity) {
- $aTemp = explode(',', $sHSL);
- $aTemp[2] += $iLuminosity;
- if ($aTemp[2] < 0) return $aTemp[0].','.$aTemp[1].',0';
- elseif ($aTemp[2] > 240) return $aTemp[0].','.$aTemp[1].',240';
- else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégée "HSLChangeSaturation" : Retourne la chaîne HSL du paramètre "$sHSL" en ayant modifier la saturation suivant le nombre du paramètre "$iSaturation".
- protected function HSLChangeSaturation($sHSL, $iSaturation) {
- $aTemp = explode(',', $sHSL);
- $aTemp[1] += $iSaturation;
- if ($aTemp[1] < 0) return $aTemp[0].',0,'.$aTemp[2];
- elseif ($aTemp[1] > 240) return $aTemp[0].',240,'.$aTemp[2];
- else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégée "HSLtoHex" : Retourne une chaîne Hexadécimale suivant la chaîne HSL du paramètre "$sHSL".
- protected function HSLtoHex($sHSL) {
- $aTemp = explode(',', $sHSL);
- $iH0 = (6*$aTemp[0])/360;
- $iMax = 255*($aTemp[2]/240);
- $iDelta = $iMax*($aTemp[1]/240);
- $iMin = $iMax-$iDelta;
- switch ((int) $iH0) {
- case 0:
- return sprintf('%02X%02X%02X', round($iMax), round($iMin+$iH0*$iDelta), round($iMin));
- break;
- case 1:
- return sprintf('%02X%02X%02X', round($iMin+(2-$iH0)*$iDelta), round($iMax), round($iMin));
- break;
- case 2:
- return sprintf('%02X%02X%02X', round($iMin), round($iMax), round($iMin+($iH0-2)*$iDelta));
- break;
- case 3:
- return sprintf('%02X%02X%02X', round($iMin), round($iMin+(4-$iH0)*$iDelta), round($iMax));
- break;
- case 4:
- return sprintf('%02X%02X%02X', round($iMin+($iH0-4)*$iDelta), round($iMin), round($iMax));
- break;
- case 5:
- return sprintf('%02X%02X%02X', round($iMax), round($iMin), round($iMin+(6-$iH0)*$iDelta));
- break;
- }
- }
-
- // Méthode protégée "HSLtoName" : Retourne le nom d'une couleur suivant la chaîne HSL du paramètre "$sHSL", sinon retourne NULL si le nom de la couleur n'est pas trouvé dans le fichier Colors.
- protected function HSLtoName($sHSL) {
- $aXpath = self::$oXml->xpath('//color[@hsl="'.$sHSL.'"]');
- if (end($aXpath) === FALSE) return NULL;
- return (string) end($aXpath)->attributes()->name;
- }
-
- // Méthode protégée "HSLtoRGB" : Retourne une chaîne RGB suivant la chaîne HSL du paramètre "$sHSL".
- protected function HSLtoRGB($sHSL) {
- $aTemp = explode(',', $sHSL);
- $iH0 = (6*$aTemp[0])/360;
- $iMax = 255*($aTemp[2]/240);
- $iDelta = $iMax*($aTemp[1]/240);
- $iMin = $iMax-$iDelta;
- switch ((int) $iH0) {
- case 0:
- return round($iMax).','.round($iMin+$iH0*$iDelta).','.round($iMin);
- break;
- case 1:
- return round($iMin+(2-$iH0)*$iDelta).','.round($iMax).','.round($iMin);
- break;
- case 2:
- return round($iMin).','.round($iMax).','.round($iMin+($iH0-2)*$iDelta);
- break;
- case 3:
- return round($iMin).','.round($iMin+(4-$iH0)*$iDelta).','.round($iMax);
- break;
- case 4:
- return round($iMin+($iH0-4)*$iDelta).','.round($iMin).','.round($iMax);
- break;
- case 5:
- return round($iMax).','.round($iMin).','.round($iMin+(6-$iH0)*$iDelta);
- break;
- }
- }
-
- // Méthode protégé "InverseHex" : Retourne la chaîne hexadécimale inverse à la chaîne héxadécimal du paramètre "$sHex".
- protected function InverseHex($sHex) {
- return strtr($sHex, array('0' => 'F', '1' => 'E', '2' => 'D', '3' => 'C', '4' => 'B', '5' => 'A', '6' => '9', '7' => '8', '8' => '7', '9' => '6', 'A' => '5', 'B' => '4', 'C' => '3', 'D' => '2', 'E' => '1', 'F' => '0'));
- }
-
- // Méthode protégé "InverseHSL" : Retourne la chaîne HSL inverse à la chaîne HSL du paramètre "$sHSL".
- protected function InverseHSL($sHSL) {
- $aTemp = explode(',', $sHSL);
- $iMin = 255*($aTemp[2]/240);
- $iDelta = $iMin*($aTemp[1]/240);
- $iMax = $iMin-$iDelta;
- $iMin = 255-$iMin;
- $iMax = 255-$iMax;
- $aTemp[0] -= 180;
- if ($aTemp[0] < 0) $aTemp[0] = 360+$aTemp[0];
- $aTemp[2] = round((240/255)*$iMax);
- if ($aTemp[2] === 0 OR $iMax === $iMin) $aTemp[1] = 0;
- else $aTemp[1] = round(240*($iDelta/$iMax));
- return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégé "InverseName" : Retourne le nom de la couleur inverse au nom de la couleur du paramètre "$sName".
- protected function InverseName($sName) {
- $aXpath = self::$oXml->xpath('//color[@name="'.$sName.'"]');
- if (end($aXpath) === FALSE) return NULL;
- return (string) end($aXpath)->attributes()->inversename;
- }
-
- // Méthode protégé "InverseRGB" : Retourne la chaîne RGB inverse à la chaîne RGB du paramètre "$sRGB".
- protected function InverseRGB($sRGB) {
- $aTemp = explode(',', $sRGB);
- return (255-$aTemp[0]).','.(255-$aTemp[1]).','.(255-$aTemp[2]);
- }
-
- // Méthode protégée "is_Hex" : Retourne TRUE si le paramètre "$sHex" est une chaîne hexadécimale, sinon retourne FALSE.
- protected function is_Hex($sHex) {
- if (preg_match('`^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$`', (string) $sHex) === 0) return FALSE;
- else return TRUE;
- }
-
- // Méthode protégée "is_HSL" : Retourne TRUE si le paramètre "$sHSL" est une chaîne HSL, sinon retourne FALSE.
- protected function is_HSL($sHSL) {
- $sHSL = str_replace(' ', '', (string) $sHSL);
- $aTemp = explode(',', $sHSL);
- if (count($aTemp) !== 3) return FALSE;
- if (is_numeric($aTemp[0]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 360 AND is_numeric($aTemp[1]) AND $aTemp[1] >= 0 AND $aTemp[1] <= 240 AND is_numeric($aTemp[2]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 240) return TRUE;
- else return FALSE;
- }
-
- // Méthode protégée "is_Name" : Retourne TRUE si le paramètre "$sName" est une chaîne faisant référence à un nom de couleur du fichier Colors, sinon retourne FALSE.
- protected function is_Name($sName) {
- $aXpath = self::$oXml->xpath('//color[@name="'.strtolower((string) $sName).'"]');
- if (end($aXpath) === FALSE) return FALSE;
- else return TRUE;
- }
-
- // Méthode protégée "is_RGB" : Retourne TRUE si le paramètre "$sRGB" est une chaîne RGB, sinon retourne FALSE.
- protected function is_RGB($sRGB) {
- $sRGB = str_replace(' ', '', (string) $sRGB);
- $aTemp = explode(',', $sRGB);
- if (count($aTemp) !== 3) return FALSE;
- if (is_numeric($aTemp[0]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 255 AND is_numeric($aTemp[1]) AND $aTemp[1] >= 0 AND $aTemp[1] <= 255 AND is_numeric($aTemp[2]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 255) return TRUE;
- else return FALSE;
- }
-
- // Méthode protégée "NametoHex" : Retourne une chaîne hexadécimale suivant la chaîne du nom de la couleur du paramètre "$sName".
- protected function NametoHex($sName) {
- $aXpath = self::$oXml->xpath('//color[@name="'.strtolower($sName).'"]');
- return (string) end($aXpath)->attributes()->hex;
- }
-
- // Méthode protégée "NametoHSL" : Retourne une chaîne HSL suivant la chaîne du nom de la couleur du paramètre "$sName".
- protected function NametoHSL($sName) {
- $aXpath = self::$oXml->xpath('//color[@name="'.strtolower($sName).'"]');
- return (string) end($aXpath)->attributes()->hsl;
- }
-
- // Méthode protégée "NametoRGB" : Retourne une chaîne RGB suivant la chaîne du nom de la couleur du paramètre "$sName".
- protected function NametoRGB($sName) {
- $aXpath = self::$oXml->xpath('//color[@name="'.strtolower($sName).'"]');
- return (string) end($aXpath)->attributes()->rgb;
- }
-
- // Méthode protégée "RemoveColorHex" : Retourne la soustraction de la chaîne Hex du paramètre "$sHex1" et de la chaîne Hex du paramètre "$sHex2".
- protected function RemoveColorHex($sHex1, $sHex2) {
- $aFinal[0] = hexdec(substr($sHex1, 0, 2))-hexdec(substr($sHex2, 0, 2));
- if ($aFinal[0] < 0) $aFinal[0] = 0;
- $aFinal[1] = hexdec(substr($sHex1, 2, 2))-hexdec(substr($sHex2, 2, 2));
- if ($aFinal[1] < 0) $aFinal[1] = 0;
- $aFinal[2] = hexdec(substr($sHex1, 4, 2))-hexdec(substr($sHex2, 4, 2));
- if ($aFinal[2] < 0) $aFinal[2] = 0;
- return sprintf('%02X%02X%02X', $aFinal[0], $aFinal[1], $aFinal[2]);
- }
-
- // Méthode protégée "RemoveColorRGB" : Retourne la soustraction de la chaîne RGB du paramètre "$sRGB1" et de la chaîne RGB du paramètre "$sRGB2".
- protected function RemoveColorRGB($sRGB1, $sRGB2) {
- $aTemp = array(explode(',', $sRGB1), explode(',', $sRGB2));
- $aFinal = array($aTemp[0][0]-$aTemp[1][0], $aTemp[0][1]-$aTemp[1][1], $aTemp[0][2]-$aTemp[1][2]);
- if ($aFinal[0] < 0) $aFinal[0] = 0;
- if ($aFinal[1] < 0) $aFinal[1] = 0;
- if ($aFinal[2] < 0) $aFinal[2] = 0;
- return $aFinal[0].','.$aFinal[1].','.$aFinal[2];
- }
-
- // Méthode protégée "RGB255toRGBother" : Retourne la chaîne RGB du paramètre "$sRGN" convertie pour avoir comme valeur maximale le nombre "$iMax".
- protected function RGB255toRGBother($sRGB, $iMax) {
- $aTemp = explode(',', $sRGB);
- return round($aTemp[0]/255*$iMax).','.round($aTemp[1]/255*$iMax).','.round($aTemp[2]/255*$iMax);
- }
-
- // Méthode protégée "RGBChangeBlue" : Retourne la chaîne RGB du paramètre "$sRGB" en ayant modifier le bleu suivant le nombre du paramètre "$iBlue".
- protected function RGBChangeBlue($sRGB, $iBlue) {
- $aTemp = explode(',', $sRGB);
- $aTemp[2] += $iBlue;
- if ($aTemp[2] < 0) return $aTemp[0].','.$aTemp[1].',0';
- elseif ($aTemp[2] > 255) return $aTemp[0].','.$aTemp[1].',255';
- else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégée "RGBChangeGreen" : Retourne la chaîne RGB du paramètre "$sRGB" en ayant modifier le vert suivant le nombre du paramètre "$iGreen".
- protected function RGBChangeGreen($sRGB, $iGreen) {
- $aTemp = explode(',', $sRGB);
- $aTemp[1] += $iGreen;
- if ($aTemp[1] < 0) return $aTemp[0].',0,'.$aTemp[2];
- elseif ($aTemp[1] > 255) return $aTemp[0].',255,'.$aTemp[2];
- else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégée "RGBChangeRed" : Retourne la chaîne RGB du paramètre "$sRGB" en ayant modifier le rouge suivant le nombre du paramètre "$iRed".
- protected function RGBChangeRed($sRGB, $iRed) {
- $aTemp = explode(',', $sRGB);
- $aTemp[0] += $iRed;
- if ($aTemp[0] < 0) return '0,'.$aTemp[1].','.$aTemp[2];
- elseif ($aTemp[0] > 255) return '255,'.$aTemp[1].','.$aTemp[2];
- else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
- }
-
- // Méthode protégée "RGBtoHex" : Retourne une chaîne hexadécimale suivant la chaîne RGB du paramètre "$sRGB".
- // Méthode corrigée (voir le commentaire de "jon at ovbb dot org" sur "http://www.php.net/manual/fr/function.dechex.php".
- protected function RGBtoHex($sRGB) {
- $aTemp = explode(',', $sRGB);
- return sprintf('%02X%02X%02X', $aTemp[0], $aTemp[1], $aTemp[2]);
- }
-
- // Méthode protégée "RGBtoHSL" : Retourne une chaîne HSL suivant la chaîne RGB du paramètre "$sRGB".
- protected function RGBtoHSL($sRGB) {
- $aTemp = explode(',', $sRGB);
- $iMax = max($aTemp[0], $aTemp[1], $aTemp[2]);
- $iMin = min($aTemp[0], $aTemp[1], $aTemp[2]);
- $iDelta = $iMax-$iMin;
- if ($iDelta === 0) $iH = 160;
- elseif ($iMax === $aTemp[0]) {
- if ($aTemp[1] >= $aTemp[2]) $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta));
- else $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta)+360);
- }
- elseif ($iMax === $aTemp[1]) $iH = round(60*(($aTemp[2]-$aTemp[0])/$iDelta)+120);
- else $iH = round(60*(($aTemp[0]-$aTemp[1])/$iDelta)+240);
- $iL = round(240/255*$iMax);
- if ($iL === 0 OR $iMax === $iMin) $iS = 0;
- else $iS = round(240*($iDelta/$iMax));
- return $iH.','.$iS.','.$iL;
- }
-
- // Méthode protégée "RGBtoName" : Retourne le nom d'une couleur suivant la chaîne RGB du paramètre "$sRGB", sinon retourne NULL si le nom de la couleur n'est pas trouvé dans le fichier Colors.
- protected function RGBtoName($sRGB) {
- $aXpath = self::$oXml->xpath('//color[@rgb="'.$sRGB.'"]');
- if (end($aXpath) === FALSE) return NULL;
- return (string) end($aXpath)->attributes()->name;
- }
-
- }
-
- class Color extends ConvertColor {
- private $aColor = array('Hex' => NULL, 'HSL' => NULL, 'Name' => NULL, 'RGB' => NULL);
-
- // Constructeur optimisé sur les conseils de Kankrelune.
- public function __construct($sColor) {
- parent::__construct();
- $sColor = str_replace(array(' ', '#'), '', (string) $sColor);
- if ($this->is_Hex($sColor) === TRUE) {
- $sColor = $this->Hex3toHex6(strtoupper($sColor));
- $this->aColor = array('Hex' => $sColor, 'HSL' => $this->HextoHSL($sColor), 'Name' => $this->HextoName($sColor), 'RGB' => $this->HextoRGB($sColor));
- }
- elseif ($this->is_Name($sColor) === TRUE) $this->aColor = array('Hex' => $this->NametoHex($sColor), 'HSL' => $this->NametoHSL($sColor), 'Name' => strtolower($sColor), 'RGB' => $this->NametoRGB($sColor));
- elseif ($this->is_RGB($sColor) === TRUE) $this->aColor = array('Hex' => $this->RGBtoHex($sColor), 'HSL' => $this->RGBtoHSL($sColor), 'Name' => $this->RGBtoName($sColor), 'RGB' => $sColor);
- else throw new Exception('Le paramètre "'.$sColor.'" n\'est pas valide.');
- }
-
- public function AddColor($oColor) {
- if ($oColor instanceof Color === FALSE) $oColor = new $this($oColor);
- $this->aColor['Hex'] = $this->AddColorHex($this->aColor['Hex'], $oColor->ColorHex());
- $this->aColor['HSL'] = $this->HextoHSL($this->aColor['Hex']);
- $this->aColor['Name'] = $this->HextoName($this->aColor['Hex']);
- $this->aColor['RGB'] = $this->AddColorRGB($this->aColor['RGB'], $oColor->ColorRGB());
- }
-
- public function ColorHex() {
- return $this->aColor['Hex'];
- }
-
- public function ColorHSL($iMax = 240) {
- if (is_numeric($iMax) AND $iMax !== 240) return $this->HSL240toHSLother($this->aColor['HSL'], (int) $iMax);
- else return $this->aColor['HSL'];
- }
-
- public function ColorInverse() {
- $this->aColor['Hex'] = $this->InverseHex($this->aColor['Hex']);
- $this->aColor['Name'] = $this->InverseName($this->aColor['Name']);
- $this->aColor['RGB'] = $this->InverseRGB($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->InverseHSL($this->aColor['HSL']);
- }
-
- public function ColorLessBlue($iBlue = 10) {
- if (is_numeric($iBlue) AND $iBlue > 0) {
- $this->aColor['RGB'] = $this->RGBChangeBlue($this->aColor['RGB'], -round($iBlue));
- $this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
- $this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
- }
- }
-
- public function ColorLessGreen($iGreen = 10) {
- if (is_numeric($iGreen) AND $iGreen > 0) {
- $this->aColor['RGB'] = $this->RGBChangeGreen($this->aColor['RGB'], -round($iGreen));
- $this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
- $this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
- }
- }
-
- public function ColorLessHue($iHue = 10) {
- if (is_numeric($iHue) AND $iHue > 0) {
- $this->aColor['HSL'] = $this->HSLChangeHue($this->aColor['HSL'], -round($iHue));
- $this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
- $this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
- $this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
- }
- }
-
- public function ColorLessLuminosity($iLuminosity = 10) {
- if (is_numeric($iLuminosity) AND $iLuminosity > 0) {
- $this->aColor['HSL'] = $this->HSLChangeLuminosity($this->aColor['HSL'], -round($iLuminosity));
- $this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
- $this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
- $this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
- }
- }
-
- public function ColorLessSaturation($iSaturation = 10) {
- if (is_numeric($iSaturation) AND $iSaturation > 0) {
- $this->aColor['HSL'] = $this->HSLChangeSaturation($this->aColor['HSL'], -round($iSaturation));
- $this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
- $this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
- $this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
- }
- }
-
- public function ColorLessRed($iRed = 10) {
- if (is_numeric($iRed) AND $iRed > 0) {
- $this->aColor['RGB'] = $this->RGBChangeRed($this->aColor['RGB'], -round($iRed));
- $this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
- $this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
- }
- }
-
- public function ColorMoreBlue($iBlue = 10) {
- if (is_numeric($iBlue) AND $iBlue > 0) {
- $this->aColor['RGB'] = $this->RGBChangeBlue($this->aColor['RGB'], round($iBlue));
- $this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
- $this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
- }
- }
-
- public function ColorMoreGreen($iGreen = 10) {
- if (is_numeric($iGreen) AND $iGreen > 0) {
- $this->aColor['RGB'] = $this->RGBChangeGreen($this->aColor['RGB'], round($iGreen));
- $this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
- $this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
- }
- }
-
- public function ColorMoreHue($iHue = 10) {
- if (is_numeric($iHue) AND $iHue > 0) {
- $this->aColor['HSL'] = $this->HSLChangeHue($this->aColor['HSL'], round($iHue));
- $this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
- $this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
- $this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
- }
- }
-
- public function ColorMoreLuminosity($iLuminosity = 10) {
- if (is_numeric($iLuminosity) AND $iLuminosity > 0) {
- $this->aColor['HSL'] = $this->HSLChangeLuminosity($this->aColor['HSL'], round($iLuminosity));
- $this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
- $this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
- $this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
- }
- }
-
- public function ColorMoreSaturation($iSaturation = 10) {
- if (is_numeric($iSaturation) AND $iSaturation > 0) {
- $this->aColor['HSL'] = $this->HSLChangeSaturation($this->aColor['HSL'], round($iSaturation));
- $this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
- $this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
- $this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
- }
- }
-
- public function ColorMoreRed($iRed = 10) {
- if (is_numeric($iRed) AND $iRed > 0) {
- $this->aColor['RGB'] = $this->RGBChangeRed($this->aColor['RGB'], round($iRed));
- $this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
- $this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
- $this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
- }
- }
-
- public function ColorName() {
- return $this->aColor['Name'];
- }
-
- public function ColorRGB($iMax = 255) {
- if (is_numeric($iMax) AND $iMax !== 255) return $this->RGB255toRGBother($this->aColor['RGB'], (int) $iMax);
- else return $this->aColor['RGB'];
- }
-
- public function RemoveColor($oColor) {
- if ($oColor instanceof Color === FALSE) $oColor = new $this($oColor);
- $this->aColor['Hex'] = $this->RemoveColorHex($this->aColor['Hex'], $oColor->ColorHex());
- $this->aColor['HSL'] = $this->HextoHSL($this->aColor['Hex']);
- $this->aColor['Name'] = $this->HextoName($this->aColor['Hex']);
- $this->aColor['RGB'] = $this->RemoveColorRGB($this->aColor['RGB'], $oColor->ColorRGB());
- }
-
- }
-
- try {
- $color1 = new Color('Red');
- echo '<span style="color:',$color1->ColorHex(),';">La couleur a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br />\r\n";
- $color1->ColorInverse();
- echo '<span style="color:',$color1->ColorHex(),';">La couleur inverse a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br />\r\n";
- $color1->AddColor('Red');
- echo '<span style="color:',$color1->ColorHex(),';">La couleur inverse additionner à la couleur rouge, a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br />\r\n";
- $color1->RemoveColor('Cyan');
- echo '<span style="color:',$color1->ColorHex(),';">La couleur moins la couleur cyan, a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br /><br />\r\n\r\n";
-
- $color2 = new Color('4682B4');
- echo '<span style="color:',$color2->ColorHex(),';">La couleur a pour nom "',$color2->ColorName(),'" a pour code Hexadécimal "',$color2->ColorHex(),'" a pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
- $color2->ColorMoreBlue(60);
- echo '<span style="color:',$color2->ColorHex(),';">La couleur avec plus de bleu a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
- $color2->ColorLessGreen(60);
- echo '<span style="color:',$color2->ColorHex(),';">La couleur avec moins de vert a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
- $color2->ColorMoreRed(60);
- echo '<span style="color:',$color2->ColorHex(),';">La couleur avec plus de rouge a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
- $color2->ColorInverse();
- echo '<span style="color:',$color2->ColorHex(),';">La couleur inverse a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br /><br />\r\n\r\n";
-
- $color3 = new Color('72,61,139');
- echo '<span style="color:',$color3->ColorHex(),';">La couleur a pour nom "',$color3->ColorName(),'" a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
- $color3->ColorMoreLuminosity(60);
- echo '<span style="color:',$color3->ColorHex(),';">La couleur avec plus de luminosité a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
- $color3->ColorLessHue(60);
- echo '<span style="color:',$color3->ColorHex(),';">La couleur avec moins de teinte a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
- $color3->ColorMoreSaturation(60);
- echo '<span style="color:',$color3->ColorHex(),';">La couleur avec plus de saturation a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
- $color3->ColorInverse();
- echo '<span style="color:',$color3->ColorHex(),';">La couleur inverse a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br /><br />\r\n\r\n";
- }
- catch (Exception $e) {
- echo $e;
- }
-
- ?>
<?php
abstract class ConvertColor {
// Constante de Class "__COLORSFILE__" : Contient le chemin du fichier Colors.
const __COLORSFILE__ = 'Colors.xml';
// Propriété privée et statique "$oXML" : Contient l'objet SimpleXML du fichier Colors.
private static $oXml;
// Méthode protégée" __construct" : Lit le fichier Colors.
protected function __construct() {
if (!isset($oXML)) {
if (!is_file(self::__COLORSFILE__)) throw new Exception('Le fichier "'.self::__COLORSFILE.'" est manquant.');
clearstatcache();
self::$oXml = simplexml_load_file(self::__COLORSFILE__);
if (self::$oXml === FALSE) throw new Exception('Erreur dans le fichier "'.self::__COLORSFILE.'".');
}
}
// Méthode protégée "AddColorHex" : Retourne l'addition de la chaîne Hex du paramètre "$sHex" et de la chaîne Hex du paramètre "$sHex2".
protected function AddColorHex($sHex1, $sHex2) {
$aFinal[0] = hexdec(substr($sHex1, 0, 2))+hexdec(substr($sHex2, 0, 2));
if ($aFinal[0] > 255) $aFinal[0] = 255;
$aFinal[1] = hexdec(substr($sHex1, 2, 2))+hexdec(substr($sHex2, 2, 2));
if ($aFinal[1] > 255) $aFinal[1] = 255;
$aFinal[2] = hexdec(substr($sHex1, 4, 2))+hexdec(substr($sHex2, 4, 2));
if ($aFinal[2] > 255) $aFinal[2] = 255;
return sprintf('%02X%02X%02X', $aFinal[0], $aFinal[1], $aFinal[2]);
}
// Méthode protégée "AddColorRGB" : Retourne l'addition de la chaîne RGB du paramètre "$sRGB1" et de la chaîne RGB du paramètre "$sRGB2".
protected function AddColorRGB($sRGB1, $sRGB2) {
$aTemp = array(explode(',', $sRGB1), explode(',', $sRGB2));
$aFinal = array($aTemp[0][0]+$aTemp[1][0], $aTemp[0][1]+$aTemp[1][1], $aTemp[0][2]+$aTemp[1][2]);
if ($aFinal[0] > 255) $aFinal[0] = 255;
if ($aFinal[1] > 255) $aFinal[1] = 255;
if ($aFinal[2] > 255) $aFinal[2] = 255;
return $aFinal[0].','.$aFinal[1].','.$aFinal[2];
}
// Méthode protégée "Hex3toHex6" : Retourne une chaîne hexadécimale de 6 nombres suivant la chaîne hexadécimale du paramètre "$sHex".
protected function Hex3toHex6($sHex) {
if (strlen($sHex) === 3) {
$sHex = substr_replace($sHex, '0', 0, 0);
$sHex = substr_replace($sHex, '0', 2, 0);
$sHex = substr_replace($sHex, '0', 4, 0);
}
return $sHex;
}
// Méthode protégée "HextoHSL" : Retourne la chaîne HSL suivant la chaîne hexadécimale du paramètre "$sHex".
protected function HextoHSL($sHex) {
$aTemp = array(hexdec(substr($sHex, 0, 2)), hexdec(substr($sHex, 2, 2)), hexdec(substr($sHex, 4, 2)));
$iMax = max($aTemp[0], $aTemp[1], $aTemp[2]);
$iMin = min($aTemp[0], $aTemp[1], $aTemp[2]);
$iDelta = $iMax-$iMin;
if ($iDelta === 0) $iH = 160;
elseif ($iMax === $aTemp[0]) {
if ($aTemp[1] >= $aTemp[2]) $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta));
else $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta)+360);
}
elseif ($iMax === $aTemp[1]) $iH = round(60*(($aTemp[2]-$aTemp[0])/$iDelta)+120);
else $iH = round(60*(($aTemp[0]-$aTemp[1])/$iDelta)+240);
$iL = round(240/255*$iMax);
if ($iL === 0 OR $iMax === $iMin) $iS = 0;
else $iS = round(240*($iDelta/$iMax));
return $iH.','.$iS.','.$iL;
}
// Méthode protégée "HextoName" : Retourne le nom d'une couleur suivant la chaîne hexadécimale du paramètre "$sHex", sinon retourne NULL si le nom de la couleur n'est pas trouvé dans le fichier Colors.
protected function HextoName($sHex) {
$aXpath = self::$oXml->xpath('//color[@hex="'.strtoupper($sHex).'"]');
if (end($aXpath) === FALSE) return NULL;
return (string) end($aXpath)->attributes()->name;
}
// Méthode protégée "HextoRGB" : Retourne une chaîne RGB suivant la chaîne hexadécimale du paramètre "$sHex".
protected function HextoRGB($sHex) {
return hexdec(substr($sHex, 0, 2)).','.hexdec(substr($sHex, 2, 2)).','.hexdec(substr($sHex, 4, 2));
}
// Méthode protégée "HSL240toHSLother" : Retourne la chaîne HSL du paramètre "$sHSL" convertie pour avoir comme valeur maximale le nombre "$iMax".
protected function HSL240toHSLother($sHSL, $iMax) {
$aTemp = explode(',', $sHSL);
return $aTemp[0].','.round($aTemp[1]/240*$iMax).','.round($aTemp[2]/240*$iMax);
}
// Méthode protégée "HSLChangeHue" : Retourne la chaîne HSL du paramètre "$sHSL" en ayant modifier la teite suivant le nombre du paramètre "$iHue".
protected function HSLChangeHue($sHSL, $iHue) {
$aTemp = explode(',', $sHSL);
$aTemp[0] = ($aTemp[0]+$iHue)%360;
if ($aTemp[0] < 0) return (360+$aTemp[0]).','.$aTemp[1].','.$aTemp[2];
return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégée "HSLChangeLuminosity" : Retourne la chaîne HSL du paramètre "$sHSL" en ayant modifier la luminosité suivant le nombre du paramètre "$iLuminosity".
protected function HSLChangeLuminosity($sHSL, $iLuminosity) {
$aTemp = explode(',', $sHSL);
$aTemp[2] += $iLuminosity;
if ($aTemp[2] < 0) return $aTemp[0].','.$aTemp[1].',0';
elseif ($aTemp[2] > 240) return $aTemp[0].','.$aTemp[1].',240';
else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégée "HSLChangeSaturation" : Retourne la chaîne HSL du paramètre "$sHSL" en ayant modifier la saturation suivant le nombre du paramètre "$iSaturation".
protected function HSLChangeSaturation($sHSL, $iSaturation) {
$aTemp = explode(',', $sHSL);
$aTemp[1] += $iSaturation;
if ($aTemp[1] < 0) return $aTemp[0].',0,'.$aTemp[2];
elseif ($aTemp[1] > 240) return $aTemp[0].',240,'.$aTemp[2];
else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégée "HSLtoHex" : Retourne une chaîne Hexadécimale suivant la chaîne HSL du paramètre "$sHSL".
protected function HSLtoHex($sHSL) {
$aTemp = explode(',', $sHSL);
$iH0 = (6*$aTemp[0])/360;
$iMax = 255*($aTemp[2]/240);
$iDelta = $iMax*($aTemp[1]/240);
$iMin = $iMax-$iDelta;
switch ((int) $iH0) {
case 0:
return sprintf('%02X%02X%02X', round($iMax), round($iMin+$iH0*$iDelta), round($iMin));
break;
case 1:
return sprintf('%02X%02X%02X', round($iMin+(2-$iH0)*$iDelta), round($iMax), round($iMin));
break;
case 2:
return sprintf('%02X%02X%02X', round($iMin), round($iMax), round($iMin+($iH0-2)*$iDelta));
break;
case 3:
return sprintf('%02X%02X%02X', round($iMin), round($iMin+(4-$iH0)*$iDelta), round($iMax));
break;
case 4:
return sprintf('%02X%02X%02X', round($iMin+($iH0-4)*$iDelta), round($iMin), round($iMax));
break;
case 5:
return sprintf('%02X%02X%02X', round($iMax), round($iMin), round($iMin+(6-$iH0)*$iDelta));
break;
}
}
// Méthode protégée "HSLtoName" : Retourne le nom d'une couleur suivant la chaîne HSL du paramètre "$sHSL", sinon retourne NULL si le nom de la couleur n'est pas trouvé dans le fichier Colors.
protected function HSLtoName($sHSL) {
$aXpath = self::$oXml->xpath('//color[@hsl="'.$sHSL.'"]');
if (end($aXpath) === FALSE) return NULL;
return (string) end($aXpath)->attributes()->name;
}
// Méthode protégée "HSLtoRGB" : Retourne une chaîne RGB suivant la chaîne HSL du paramètre "$sHSL".
protected function HSLtoRGB($sHSL) {
$aTemp = explode(',', $sHSL);
$iH0 = (6*$aTemp[0])/360;
$iMax = 255*($aTemp[2]/240);
$iDelta = $iMax*($aTemp[1]/240);
$iMin = $iMax-$iDelta;
switch ((int) $iH0) {
case 0:
return round($iMax).','.round($iMin+$iH0*$iDelta).','.round($iMin);
break;
case 1:
return round($iMin+(2-$iH0)*$iDelta).','.round($iMax).','.round($iMin);
break;
case 2:
return round($iMin).','.round($iMax).','.round($iMin+($iH0-2)*$iDelta);
break;
case 3:
return round($iMin).','.round($iMin+(4-$iH0)*$iDelta).','.round($iMax);
break;
case 4:
return round($iMin+($iH0-4)*$iDelta).','.round($iMin).','.round($iMax);
break;
case 5:
return round($iMax).','.round($iMin).','.round($iMin+(6-$iH0)*$iDelta);
break;
}
}
// Méthode protégé "InverseHex" : Retourne la chaîne hexadécimale inverse à la chaîne héxadécimal du paramètre "$sHex".
protected function InverseHex($sHex) {
return strtr($sHex, array('0' => 'F', '1' => 'E', '2' => 'D', '3' => 'C', '4' => 'B', '5' => 'A', '6' => '9', '7' => '8', '8' => '7', '9' => '6', 'A' => '5', 'B' => '4', 'C' => '3', 'D' => '2', 'E' => '1', 'F' => '0'));
}
// Méthode protégé "InverseHSL" : Retourne la chaîne HSL inverse à la chaîne HSL du paramètre "$sHSL".
protected function InverseHSL($sHSL) {
$aTemp = explode(',', $sHSL);
$iMin = 255*($aTemp[2]/240);
$iDelta = $iMin*($aTemp[1]/240);
$iMax = $iMin-$iDelta;
$iMin = 255-$iMin;
$iMax = 255-$iMax;
$aTemp[0] -= 180;
if ($aTemp[0] < 0) $aTemp[0] = 360+$aTemp[0];
$aTemp[2] = round((240/255)*$iMax);
if ($aTemp[2] === 0 OR $iMax === $iMin) $aTemp[1] = 0;
else $aTemp[1] = round(240*($iDelta/$iMax));
return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégé "InverseName" : Retourne le nom de la couleur inverse au nom de la couleur du paramètre "$sName".
protected function InverseName($sName) {
$aXpath = self::$oXml->xpath('//color[@name="'.$sName.'"]');
if (end($aXpath) === FALSE) return NULL;
return (string) end($aXpath)->attributes()->inversename;
}
// Méthode protégé "InverseRGB" : Retourne la chaîne RGB inverse à la chaîne RGB du paramètre "$sRGB".
protected function InverseRGB($sRGB) {
$aTemp = explode(',', $sRGB);
return (255-$aTemp[0]).','.(255-$aTemp[1]).','.(255-$aTemp[2]);
}
// Méthode protégée "is_Hex" : Retourne TRUE si le paramètre "$sHex" est une chaîne hexadécimale, sinon retourne FALSE.
protected function is_Hex($sHex) {
if (preg_match('`^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$`', (string) $sHex) === 0) return FALSE;
else return TRUE;
}
// Méthode protégée "is_HSL" : Retourne TRUE si le paramètre "$sHSL" est une chaîne HSL, sinon retourne FALSE.
protected function is_HSL($sHSL) {
$sHSL = str_replace(' ', '', (string) $sHSL);
$aTemp = explode(',', $sHSL);
if (count($aTemp) !== 3) return FALSE;
if (is_numeric($aTemp[0]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 360 AND is_numeric($aTemp[1]) AND $aTemp[1] >= 0 AND $aTemp[1] <= 240 AND is_numeric($aTemp[2]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 240) return TRUE;
else return FALSE;
}
// Méthode protégée "is_Name" : Retourne TRUE si le paramètre "$sName" est une chaîne faisant référence à un nom de couleur du fichier Colors, sinon retourne FALSE.
protected function is_Name($sName) {
$aXpath = self::$oXml->xpath('//color[@name="'.strtolower((string) $sName).'"]');
if (end($aXpath) === FALSE) return FALSE;
else return TRUE;
}
// Méthode protégée "is_RGB" : Retourne TRUE si le paramètre "$sRGB" est une chaîne RGB, sinon retourne FALSE.
protected function is_RGB($sRGB) {
$sRGB = str_replace(' ', '', (string) $sRGB);
$aTemp = explode(',', $sRGB);
if (count($aTemp) !== 3) return FALSE;
if (is_numeric($aTemp[0]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 255 AND is_numeric($aTemp[1]) AND $aTemp[1] >= 0 AND $aTemp[1] <= 255 AND is_numeric($aTemp[2]) AND $aTemp[0] >= 0 AND $aTemp[0] <= 255) return TRUE;
else return FALSE;
}
// Méthode protégée "NametoHex" : Retourne une chaîne hexadécimale suivant la chaîne du nom de la couleur du paramètre "$sName".
protected function NametoHex($sName) {
$aXpath = self::$oXml->xpath('//color[@name="'.strtolower($sName).'"]');
return (string) end($aXpath)->attributes()->hex;
}
// Méthode protégée "NametoHSL" : Retourne une chaîne HSL suivant la chaîne du nom de la couleur du paramètre "$sName".
protected function NametoHSL($sName) {
$aXpath = self::$oXml->xpath('//color[@name="'.strtolower($sName).'"]');
return (string) end($aXpath)->attributes()->hsl;
}
// Méthode protégée "NametoRGB" : Retourne une chaîne RGB suivant la chaîne du nom de la couleur du paramètre "$sName".
protected function NametoRGB($sName) {
$aXpath = self::$oXml->xpath('//color[@name="'.strtolower($sName).'"]');
return (string) end($aXpath)->attributes()->rgb;
}
// Méthode protégée "RemoveColorHex" : Retourne la soustraction de la chaîne Hex du paramètre "$sHex1" et de la chaîne Hex du paramètre "$sHex2".
protected function RemoveColorHex($sHex1, $sHex2) {
$aFinal[0] = hexdec(substr($sHex1, 0, 2))-hexdec(substr($sHex2, 0, 2));
if ($aFinal[0] < 0) $aFinal[0] = 0;
$aFinal[1] = hexdec(substr($sHex1, 2, 2))-hexdec(substr($sHex2, 2, 2));
if ($aFinal[1] < 0) $aFinal[1] = 0;
$aFinal[2] = hexdec(substr($sHex1, 4, 2))-hexdec(substr($sHex2, 4, 2));
if ($aFinal[2] < 0) $aFinal[2] = 0;
return sprintf('%02X%02X%02X', $aFinal[0], $aFinal[1], $aFinal[2]);
}
// Méthode protégée "RemoveColorRGB" : Retourne la soustraction de la chaîne RGB du paramètre "$sRGB1" et de la chaîne RGB du paramètre "$sRGB2".
protected function RemoveColorRGB($sRGB1, $sRGB2) {
$aTemp = array(explode(',', $sRGB1), explode(',', $sRGB2));
$aFinal = array($aTemp[0][0]-$aTemp[1][0], $aTemp[0][1]-$aTemp[1][1], $aTemp[0][2]-$aTemp[1][2]);
if ($aFinal[0] < 0) $aFinal[0] = 0;
if ($aFinal[1] < 0) $aFinal[1] = 0;
if ($aFinal[2] < 0) $aFinal[2] = 0;
return $aFinal[0].','.$aFinal[1].','.$aFinal[2];
}
// Méthode protégée "RGB255toRGBother" : Retourne la chaîne RGB du paramètre "$sRGN" convertie pour avoir comme valeur maximale le nombre "$iMax".
protected function RGB255toRGBother($sRGB, $iMax) {
$aTemp = explode(',', $sRGB);
return round($aTemp[0]/255*$iMax).','.round($aTemp[1]/255*$iMax).','.round($aTemp[2]/255*$iMax);
}
// Méthode protégée "RGBChangeBlue" : Retourne la chaîne RGB du paramètre "$sRGB" en ayant modifier le bleu suivant le nombre du paramètre "$iBlue".
protected function RGBChangeBlue($sRGB, $iBlue) {
$aTemp = explode(',', $sRGB);
$aTemp[2] += $iBlue;
if ($aTemp[2] < 0) return $aTemp[0].','.$aTemp[1].',0';
elseif ($aTemp[2] > 255) return $aTemp[0].','.$aTemp[1].',255';
else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégée "RGBChangeGreen" : Retourne la chaîne RGB du paramètre "$sRGB" en ayant modifier le vert suivant le nombre du paramètre "$iGreen".
protected function RGBChangeGreen($sRGB, $iGreen) {
$aTemp = explode(',', $sRGB);
$aTemp[1] += $iGreen;
if ($aTemp[1] < 0) return $aTemp[0].',0,'.$aTemp[2];
elseif ($aTemp[1] > 255) return $aTemp[0].',255,'.$aTemp[2];
else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégée "RGBChangeRed" : Retourne la chaîne RGB du paramètre "$sRGB" en ayant modifier le rouge suivant le nombre du paramètre "$iRed".
protected function RGBChangeRed($sRGB, $iRed) {
$aTemp = explode(',', $sRGB);
$aTemp[0] += $iRed;
if ($aTemp[0] < 0) return '0,'.$aTemp[1].','.$aTemp[2];
elseif ($aTemp[0] > 255) return '255,'.$aTemp[1].','.$aTemp[2];
else return $aTemp[0].','.$aTemp[1].','.$aTemp[2];
}
// Méthode protégée "RGBtoHex" : Retourne une chaîne hexadécimale suivant la chaîne RGB du paramètre "$sRGB".
// Méthode corrigée (voir le commentaire de "jon at ovbb dot org" sur "http://www.php.net/manual/fr/function.dechex.php".
protected function RGBtoHex($sRGB) {
$aTemp = explode(',', $sRGB);
return sprintf('%02X%02X%02X', $aTemp[0], $aTemp[1], $aTemp[2]);
}
// Méthode protégée "RGBtoHSL" : Retourne une chaîne HSL suivant la chaîne RGB du paramètre "$sRGB".
protected function RGBtoHSL($sRGB) {
$aTemp = explode(',', $sRGB);
$iMax = max($aTemp[0], $aTemp[1], $aTemp[2]);
$iMin = min($aTemp[0], $aTemp[1], $aTemp[2]);
$iDelta = $iMax-$iMin;
if ($iDelta === 0) $iH = 160;
elseif ($iMax === $aTemp[0]) {
if ($aTemp[1] >= $aTemp[2]) $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta));
else $iH = round(60*(($aTemp[1]-$aTemp[2])/$iDelta)+360);
}
elseif ($iMax === $aTemp[1]) $iH = round(60*(($aTemp[2]-$aTemp[0])/$iDelta)+120);
else $iH = round(60*(($aTemp[0]-$aTemp[1])/$iDelta)+240);
$iL = round(240/255*$iMax);
if ($iL === 0 OR $iMax === $iMin) $iS = 0;
else $iS = round(240*($iDelta/$iMax));
return $iH.','.$iS.','.$iL;
}
// Méthode protégée "RGBtoName" : Retourne le nom d'une couleur suivant la chaîne RGB du paramètre "$sRGB", sinon retourne NULL si le nom de la couleur n'est pas trouvé dans le fichier Colors.
protected function RGBtoName($sRGB) {
$aXpath = self::$oXml->xpath('//color[@rgb="'.$sRGB.'"]');
if (end($aXpath) === FALSE) return NULL;
return (string) end($aXpath)->attributes()->name;
}
}
class Color extends ConvertColor {
private $aColor = array('Hex' => NULL, 'HSL' => NULL, 'Name' => NULL, 'RGB' => NULL);
// Constructeur optimisé sur les conseils de Kankrelune.
public function __construct($sColor) {
parent::__construct();
$sColor = str_replace(array(' ', '#'), '', (string) $sColor);
if ($this->is_Hex($sColor) === TRUE) {
$sColor = $this->Hex3toHex6(strtoupper($sColor));
$this->aColor = array('Hex' => $sColor, 'HSL' => $this->HextoHSL($sColor), 'Name' => $this->HextoName($sColor), 'RGB' => $this->HextoRGB($sColor));
}
elseif ($this->is_Name($sColor) === TRUE) $this->aColor = array('Hex' => $this->NametoHex($sColor), 'HSL' => $this->NametoHSL($sColor), 'Name' => strtolower($sColor), 'RGB' => $this->NametoRGB($sColor));
elseif ($this->is_RGB($sColor) === TRUE) $this->aColor = array('Hex' => $this->RGBtoHex($sColor), 'HSL' => $this->RGBtoHSL($sColor), 'Name' => $this->RGBtoName($sColor), 'RGB' => $sColor);
else throw new Exception('Le paramètre "'.$sColor.'" n\'est pas valide.');
}
public function AddColor($oColor) {
if ($oColor instanceof Color === FALSE) $oColor = new $this($oColor);
$this->aColor['Hex'] = $this->AddColorHex($this->aColor['Hex'], $oColor->ColorHex());
$this->aColor['HSL'] = $this->HextoHSL($this->aColor['Hex']);
$this->aColor['Name'] = $this->HextoName($this->aColor['Hex']);
$this->aColor['RGB'] = $this->AddColorRGB($this->aColor['RGB'], $oColor->ColorRGB());
}
public function ColorHex() {
return $this->aColor['Hex'];
}
public function ColorHSL($iMax = 240) {
if (is_numeric($iMax) AND $iMax !== 240) return $this->HSL240toHSLother($this->aColor['HSL'], (int) $iMax);
else return $this->aColor['HSL'];
}
public function ColorInverse() {
$this->aColor['Hex'] = $this->InverseHex($this->aColor['Hex']);
$this->aColor['Name'] = $this->InverseName($this->aColor['Name']);
$this->aColor['RGB'] = $this->InverseRGB($this->aColor['RGB']);
$this->aColor['HSL'] = $this->InverseHSL($this->aColor['HSL']);
}
public function ColorLessBlue($iBlue = 10) {
if (is_numeric($iBlue) AND $iBlue > 0) {
$this->aColor['RGB'] = $this->RGBChangeBlue($this->aColor['RGB'], -round($iBlue));
$this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
$this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
$this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
}
}
public function ColorLessGreen($iGreen = 10) {
if (is_numeric($iGreen) AND $iGreen > 0) {
$this->aColor['RGB'] = $this->RGBChangeGreen($this->aColor['RGB'], -round($iGreen));
$this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
$this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
$this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
}
}
public function ColorLessHue($iHue = 10) {
if (is_numeric($iHue) AND $iHue > 0) {
$this->aColor['HSL'] = $this->HSLChangeHue($this->aColor['HSL'], -round($iHue));
$this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
$this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
$this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
}
}
public function ColorLessLuminosity($iLuminosity = 10) {
if (is_numeric($iLuminosity) AND $iLuminosity > 0) {
$this->aColor['HSL'] = $this->HSLChangeLuminosity($this->aColor['HSL'], -round($iLuminosity));
$this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
$this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
$this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
}
}
public function ColorLessSaturation($iSaturation = 10) {
if (is_numeric($iSaturation) AND $iSaturation > 0) {
$this->aColor['HSL'] = $this->HSLChangeSaturation($this->aColor['HSL'], -round($iSaturation));
$this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
$this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
$this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
}
}
public function ColorLessRed($iRed = 10) {
if (is_numeric($iRed) AND $iRed > 0) {
$this->aColor['RGB'] = $this->RGBChangeRed($this->aColor['RGB'], -round($iRed));
$this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
$this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
$this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
}
}
public function ColorMoreBlue($iBlue = 10) {
if (is_numeric($iBlue) AND $iBlue > 0) {
$this->aColor['RGB'] = $this->RGBChangeBlue($this->aColor['RGB'], round($iBlue));
$this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
$this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
$this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
}
}
public function ColorMoreGreen($iGreen = 10) {
if (is_numeric($iGreen) AND $iGreen > 0) {
$this->aColor['RGB'] = $this->RGBChangeGreen($this->aColor['RGB'], round($iGreen));
$this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
$this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
$this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
}
}
public function ColorMoreHue($iHue = 10) {
if (is_numeric($iHue) AND $iHue > 0) {
$this->aColor['HSL'] = $this->HSLChangeHue($this->aColor['HSL'], round($iHue));
$this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
$this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
$this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
}
}
public function ColorMoreLuminosity($iLuminosity = 10) {
if (is_numeric($iLuminosity) AND $iLuminosity > 0) {
$this->aColor['HSL'] = $this->HSLChangeLuminosity($this->aColor['HSL'], round($iLuminosity));
$this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
$this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
$this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
}
}
public function ColorMoreSaturation($iSaturation = 10) {
if (is_numeric($iSaturation) AND $iSaturation > 0) {
$this->aColor['HSL'] = $this->HSLChangeSaturation($this->aColor['HSL'], round($iSaturation));
$this->aColor['Hex'] = $this->HSLtoHex($this->aColor['HSL']);
$this->aColor['Name'] = $this->HSLtoName($this->aColor['HSL']);
$this->aColor['RGB'] = $this->HSLtoRGB($this->aColor['HSL']);
}
}
public function ColorMoreRed($iRed = 10) {
if (is_numeric($iRed) AND $iRed > 0) {
$this->aColor['RGB'] = $this->RGBChangeRed($this->aColor['RGB'], round($iRed));
$this->aColor['Hex'] = $this->RGBtoHex($this->aColor['RGB']);
$this->aColor['HSL'] = $this->RGBtoHSL($this->aColor['RGB']);
$this->aColor['Name'] = $this->RGBtoName($this->aColor['RGB']);
}
}
public function ColorName() {
return $this->aColor['Name'];
}
public function ColorRGB($iMax = 255) {
if (is_numeric($iMax) AND $iMax !== 255) return $this->RGB255toRGBother($this->aColor['RGB'], (int) $iMax);
else return $this->aColor['RGB'];
}
public function RemoveColor($oColor) {
if ($oColor instanceof Color === FALSE) $oColor = new $this($oColor);
$this->aColor['Hex'] = $this->RemoveColorHex($this->aColor['Hex'], $oColor->ColorHex());
$this->aColor['HSL'] = $this->HextoHSL($this->aColor['Hex']);
$this->aColor['Name'] = $this->HextoName($this->aColor['Hex']);
$this->aColor['RGB'] = $this->RemoveColorRGB($this->aColor['RGB'], $oColor->ColorRGB());
}
}
try {
$color1 = new Color('Red');
echo '<span style="color:',$color1->ColorHex(),';">La couleur a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br />\r\n";
$color1->ColorInverse();
echo '<span style="color:',$color1->ColorHex(),';">La couleur inverse a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br />\r\n";
$color1->AddColor('Red');
echo '<span style="color:',$color1->ColorHex(),';">La couleur inverse additionner à la couleur rouge, a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br />\r\n";
$color1->RemoveColor('Cyan');
echo '<span style="color:',$color1->ColorHex(),';">La couleur moins la couleur cyan, a pour nom "',$color1->ColorName(),'" a pour code Hexadécimal "',$color1->ColorHex(),'" et pour code RGB "',$color1->ColorRGB(),'" et a pour code HSL "',$color1->ColorHSL(),'".</span>',"<br /><br />\r\n\r\n";
$color2 = new Color('4682B4');
echo '<span style="color:',$color2->ColorHex(),';">La couleur a pour nom "',$color2->ColorName(),'" a pour code Hexadécimal "',$color2->ColorHex(),'" a pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
$color2->ColorMoreBlue(60);
echo '<span style="color:',$color2->ColorHex(),';">La couleur avec plus de bleu a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
$color2->ColorLessGreen(60);
echo '<span style="color:',$color2->ColorHex(),';">La couleur avec moins de vert a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
$color2->ColorMoreRed(60);
echo '<span style="color:',$color2->ColorHex(),';">La couleur avec plus de rouge a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br />\r\n";
$color2->ColorInverse();
echo '<span style="color:',$color2->ColorHex(),';">La couleur inverse a pour code Hexadécimal "',$color2->ColorHex(),'" et pour code RGB "',$color2->ColorRGB(),'" et a pour code HSL "',$color2->ColorHSL(),'".</span>',"<br /><br />\r\n\r\n";
$color3 = new Color('72,61,139');
echo '<span style="color:',$color3->ColorHex(),';">La couleur a pour nom "',$color3->ColorName(),'" a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
$color3->ColorMoreLuminosity(60);
echo '<span style="color:',$color3->ColorHex(),';">La couleur avec plus de luminosité a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
$color3->ColorLessHue(60);
echo '<span style="color:',$color3->ColorHex(),';">La couleur avec moins de teinte a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
$color3->ColorMoreSaturation(60);
echo '<span style="color:',$color3->ColorHex(),';">La couleur avec plus de saturation a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br />\r\n";
$color3->ColorInverse();
echo '<span style="color:',$color3->ColorHex(),';">La couleur inverse a pour code Hexadécimal "',$color3->ColorHex(),'" et pour code RGB "',$color3->ColorRGB(),'" et a pour code HSL "',$color3->ColorHSL(),'".</span>',"<br /><br />\r\n\r\n";
}
catch (Exception $e) {
echo $e;
}
?>
Conclusion
Pas de bug connu. Bien entendu si vous trouvez un bug ou si vous trouvez une amélioration, n'hésitez pas à m'en faire part ^^
Historique
- 04 août 2007 00:53:20 :
- Amélioration générale :
=> Les chaînes hexadécimales à 3 chiffres sont converties en chaînes hexadécimales à 6 chiffres.
(Ajout de la Méthode "Hex3toHex6".)
(Méthodes modifiées : "is_Hex" et "HextoRGB".)
=> Prise en charge du code HSL (Hue, Saturation, Lightness) qui permettra par la suite d'éclaisir ou d'assombrir une couleur.
(Ajouts des Méthodes "is_HSL", "HextoHSL", "HSLtoHex", "HSLtoName", "HSLtoRGB", "NametoHSL", "RGBtoHSL".)
=> Prise en charge de l'inversion de couleur.
(Ajouts des Méthodes "InverseHex", "InverseHSL", "InverseName", "InverseRGB".)
=> Optimisation du constructeur sur les conseils de Kankrelune.
- 06 août 2007 21:54:22 :
- Amélioration Générale :
=> Possibilité de changer la teinte, la saturation et la luminosité d'une couleur.
(Ajouts des Méthodes "HSLChangeHue", "HSLChangeSaturation" et "HSLChangeLuminosity")
=> Possibilité de changer le rouge, le vert et le bleu d'une couleur.
(Ajouts des Méthodes "RGBChangeRed", "RGBChangeGreen", "RGBChangeBlue")
=> Possibilité de renvoyer le code RGB et HSL avec une valeur maximale différente de celle par défaut.
(Ajouts des Méthodes "HSL240toHSLother" et "RGB255toRGBother")
- 09 août 2007 23:01:25 :
- Amélioration générale :
=> Optimisation de quelques méthodes.
(Méthodes modifiées : "InverseHSL", "HextoHSL" et "RGBtoHSL")
=> Possibilité d'additionner ou de soustraire des couleurs.
(Ajouts de Méthodes : "AddColorHex", "AddColorRGB", "RemoveColorHex" et "RemoveColorRGB".)
=> Ajouts des Exceptions dans le constructeur.
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Récuperer code RGB d'une couleur indexé [ par drof ]
bonjour a tous,je cherche comment récupérer la valeur RGB d'une couleur indexé. Je m'explique, mon script charge une image puis avec imagecolorat(), j
Quelle est la meilleure class ou library pour la gestion de bases de données ? [ par paguira ]
Bonjour,Quelle est la meilleure class ou library pour la gestion de bases de données ?Que pensez vous de ADOBDB ?Est elle maintenue ?Y a t'il un site
Class abstraite [ par abdoulax ]
Bonjour,Jusqu'à present, je n'ai réussi à faire que des classes virtuel pure. Est-t'il possible de faire des classes virtuel non pure afin de ne pas ê
passage d'image numériser en couleur en noir et blanc [ par ticetac31 ]
Bonjour, Je voudrais savoir su quelqu'un peut me dire si l'on peut d'une image numérisée en couleur la faire devenir noie et blanc sans détériorer la
function get_called_class() [ par tafsne ]
salutj'ai essayé la fonction get_called_class() en php5 avec non éditeur zend et easy php 2.0 béta mé sa ne marche passvp si vous pouvez m'aider
Tutoriel sur les CLASS [ par patric31 ]
Bonjour à toutes et à tous,Je suis à la recherche d'un tuto sur les CLASS.Quelque chose de simple, qui parte du B.A-BA pour pouvoir en créer et m'en s
Lien sur ligne tableau [ par theseif ]
Bonjour à tous, je ne sait pas si je suis dans le bon forum (php ou javascript) mais voila.Dans un tableau que j'affiche sous un formulaire j'utilise
Formulaire avec liste déroulante - demande d'aide [ par notebleue ]
Bonjour,J'ai créé une petite base de données me permettant de faire des essais sans devoir utiliser ma base réelle comportant plus de champs. Cette pe
echiquier [ par jackinfor ]
Bonjour,J'essaye pour le moment de faire un échiquier, mais comme je suis un débutant bah je bloque :)Voila mon code pour le momentMerci de m'aider<
expression reguliere [ par lili345 ]
bonjour a tous j'ai un pb j'aimerais trouver dans un code php si c'est une classe ou non donc pour cela j'utilise la fonction preg_match comme ceci
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|