note 47757 modified in function.imagecolorallocate by thiago

From: Date: Fri, 24 Apr 2009 12:30:09 +0000
Subject: note 47757 modified in function.imagecolorallocate by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153659@lists.php.net to get a copy of this message
2 functions to convert from HSV colorspace (hue/saturation/brightness) to RGB (red/green/blue) colorspace and back. <?php // $c = array($red, $green, $blue) // $red=[0..1], $green=[0..1], $blue=[0..1]; function rgb2hsv($c) { list($r,$g,$b)=$c; $v=max($r,$g,$b); $t=min($r,$g,$b); $s=($v==0)?0:($v-$t)/$v; if ($s==0) $h=-1; else { $a=$v-$t; $cr=($v-$r)/$a; $cg=($v-$g)/$a; $cb=($v-$b)/$a; $h=($r==$v)?$cb-$cg:(($g==$v)?2+$cr-$cb:(($b==$v)?$h=4+$cg-$cr:0)); $h=60*$h; $h=($h<0)?$h+360:$h; } return array($h,$s,$v); } // $c = array($hue, $saturation, $brightness) // $hue=[0..360], $saturation=[0..1], $brightness=[0..1] function hsv2rgb($c) { list($h,$s,$v)=$c; if ($s==0) return array($v,$v,$v); else { $h=($h%=360)/60; $i=floor($h); $f=$h-$i; $q[0]=$q[1]=$v*(1-$s); $q[2]=$v*(1-$s*(1-$f)); $q[3]=$q[4]=$v; $q[5]=$v*(1-$s*$f); //return(array($q[($i+4)%5],$q[($i+2)%5],$q[$i%5])); return(array($q[($i+4)%6],$q[($i+2)%6],$q[$i%6])); //[1] } } ?> [1] - EDITOR NOTE: THIS IS A FIX FROM "hc at hob(removethis)soft dot net". --was-- 2 functions to convert from HSV colorspace (hue/saturation/brightness) to RGB (red/green/blue) colorspace and back. <?php // $c = array($red, $green, $blue) // $red=[0..1], $green=[0..1], $blue=[0..1]; function rgb2hsv($c) { list($r,$g,$b)=$c; $v=max($r,$g,$b); $t=min($r,$g,$b); $s=($v==0)?0:($v-$t)/$v; if ($s==0) $h=-1; else { $a=$v-$t; $cr=($v-$r)/$a; $cg=($v-$g)/$a; $cb=($v-$b)/$a; $h=($r==$v)?$cb-$cg:(($g==$v)?2+$cr-$cb:(($b==$v)?$h=4+$cg-$cr:0)); $h=60*$h; $h=($h<0)?$h+360:$h; } return array($h,$s,$v); } // $c = array($hue, $saturation, $brightness) // $hue=[0..360], $saturation=[0..1], $brightness=[0..1] function hsv2rgb($c) { list($h,$s,$v)=$c; if ($s==0) return array($v,$v,$v); else { $h=($h%=360)/60; $i=floor($h); $f=$h-$i; $q[0]=$q[1]=$v*(1-$s); $q[2]=$v*(1-$s*(1-$f)); $q[3]=$q[4]=$v; $q[5]=$v*(1-$s*$f); return(array($q[($i+4)%5],$q[($i+2)%5],$q[$i%5])); } } ?> http://php.net/manual/en/function.imagecolorallocate.php

« previous php.notes (#153659) next »