1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| private function setCouleurs(){
$netb = true;
$niveaugris = true;
$palette = Array([0]=>Array(0,0,0), //noir
[1]=>Array(128,128,128), //gris
[2]=>Array(128,0,0), //marron
[3]=>Array(255,0,0), //rouge
[4]=>Array(0,128,0), //vertfoncé
[5]=>Array(0,255,0), //vert
[6]=>Array(128,128,0), //olive
[7]=>Array(255,255,0), //jaune
[8]=>Array(0,0,128), //marine
[9]=>Array(0,0,255), //bleu
[10]=>Array(128,0,128), //violet
[11]=>Array(255,0,255), //fuchsia
[12]=>Array(0,128,128), //cobalt
[13]=>Array(0,255,255), //aqua
[14]=>Array(192,192,192),//argent
[15]=>Array(255,255,255),//blanc
[16]=>Array(255,128,0) //orange
);
for ($i=1 ; $i < ImageSX($this->miniatureNonReechantillonnee) ; $i++) {
for ($j=1 ; $j < ImageSX($this->miniatureNonReechantillonnee) ; $j++) {
$pixel = ImageColorAt($miniatureNonReechantillonnee,$i,$j);
if ($pixel != 0 || $pixel != 255255255) $netb = false;
$r = ($pixel >> 16) & 0xFF;
$v = ($pixel >> 8) & 0xFF;
$b = $pixel & 0xFF;
if ($r != $v || $v != $b || $r != $b) $niveaugris = false;
$distMin = 1000;
for ($k=0 ; $k < count($palette) && $disMin != 0 ; $k++) {
$distance = pow($palette[$k][0] - $r,2) + pow($palette[$k][1] - $v,2) + pow($palette[$k][2] - $b,2);
if ($distance < $distMin){$disMin = $distance;$indCoulProche = $k;}
}
$paletteDom[$indCoulProche]++;
}
}
$max = 0;
foreach ($paletteDom as $key => $val)if ($val > $max)$this->couleurDominante = $key);
$this->couleurDominante = $this->couleurDominante[0].$this->couleurDominante[1].$this->couleurDominante[2];
if ($netb)$this->coloration = 1;
else if ($niveaugris)$this->coloration = 2;
else $this->coloration = 3;
} |
Partager