Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 236 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/*
 * Created on 23 juin 2011
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 
class OdsMarqueur extends JRestService {
        
        public function getElement() {
        
                if(isset($_GET['couleurs'])) {
                        $couleurs = explode(',',$_GET['couleurs']);
                }
                
                $taille = 15;
                
                if(isset($_GET['taille'])) {
                        $taille = $_GET['taille'];
                }
                
                $image = imagecreatetruecolor($taille,$taille);
                $faux_noir = imagecolorallocate($image, 64, 64, 64);
                $noir = imagecolorallocate($image, 0, 0, 0);
                
                if(count($couleurs) <= 0) {
                        return;
                }
                
                //$couleurs = array_unique($couleurs);
                sort($couleurs);
                
                $pas_angle = 360/count($couleurs);
                $angle = 0;
                
                foreach($couleurs as $couleur_html) {
                        
                        $couleur_rgb = $this->html2rgb($couleur_html);
                                                
                        $couleur_allouee = imagecolorallocate($image, $couleur_rgb[0], $couleur_rgb[1], $couleur_rgb[2]);               
                        imagefilledarc($image, $taille/2, $taille/2,
                                                        $taille, $taille-1, 
                                                        $angle, $angle+$pas_angle, 
                                                        $couleur_allouee, IMG_ARC_PIE);
                        $angle = $angle+$pas_angle;
                }
                
                imagefilledarc($image, $taille/2, $taille/2,
                                                        $taille, $taille, 
                                                        0, 360, 
                                                        $faux_noir, IMG_ARC_NOFILL);
                
                imagecolortransparent($image, $noir);
                
                header('Content-type: image/png');
                imagepng($image);
                imagedestroy($image);
        }       
        
        function html2rgb($color)
        {
            if ($color[0] == '#')
                $color = substr($color, 1);
        
            if (strlen($color) == 6)
                list($r, $g, $b) = array($color[0].$color[1],
                                         $color[2].$color[3],
                                         $color[4].$color[5]);
            elseif (strlen($color) == 3)
                list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
            else
                return false;
        
            $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
        
            return array($r, $g, $b);
        }
}       
?>