Subversion Repositories Sites.obs-saisons.fr

Rev

Rev 236 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 236 Rev 262
1
<?php
1
<?php
2
/*
2
/*
3
 * Created on 23 juin 2011
3
 * Created on 23 juin 2011
4
 *
4
 *
5
 * To change the template for this generated file go to
5
 * To change the template for this generated file go to
6
 * Window - Preferences - PHPeclipse - PHP - Code Templates
6
 * Window - Preferences - PHPeclipse - PHP - Code Templates
7
 */
7
 */
8
 
8
 
9
class OdsMarqueur extends JRestService {
9
class OdsMarqueur extends JRestService {
10
 	
10
 	
11
 	public function getElement() {
11
 	public function getElement() {
12
 	
12
 	
13
 		if(isset($_GET['couleurs'])) {
13
 		if(isset($_GET['couleurs'])) {
14
 			$couleurs = split(',',$_GET['couleurs']);
14
 			$couleurs = explode(',',$_GET['couleurs']);
15
 		}
15
 		}
16
 		
16
 		
17
 		$taille = 15;
17
 		$taille = 15;
18
 		
18
 		
19
 		if(isset($_GET['taille'])) {
19
 		if(isset($_GET['taille'])) {
20
 			$taille = $_GET['taille'];
20
 			$taille = $_GET['taille'];
21
 		}
21
 		}
22
 		
22
 		
23
 		$image = imagecreatetruecolor($taille,$taille);
23
 		$image = imagecreatetruecolor($taille,$taille);
24
		$faux_noir = imagecolorallocate($image, 64, 64, 64);
24
		$faux_noir = imagecolorallocate($image, 64, 64, 64);
25
		$noir = imagecolorallocate($image, 0, 0, 0);
25
		$noir = imagecolorallocate($image, 0, 0, 0);
26
 		
26
 		
27
 		if(count($couleurs) <= 0) {
27
 		if(count($couleurs) <= 0) {
28
 			return;
28
 			return;
29
 		}
29
 		}
30
 		
30
 		
31
 		//$couleurs = array_unique($couleurs);
31
 		//$couleurs = array_unique($couleurs);
32
 		sort($couleurs);
32
 		sort($couleurs);
33
 		
33
 		
34
 		$pas_angle = 360/count($couleurs);
34
 		$pas_angle = 360/count($couleurs);
35
 		$angle = 0;
35
 		$angle = 0;
36
 		
36
 		
37
 		foreach($couleurs as $couleur_html) {
37
 		foreach($couleurs as $couleur_html) {
38
 			
38
 			
39
 			$couleur_rgb = $this->html2rgb($couleur_html);
39
 			$couleur_rgb = $this->html2rgb($couleur_html);
40
 			 			
40
 			 			
41
			$couleur_allouee = imagecolorallocate($image, $couleur_rgb[0], $couleur_rgb[1], $couleur_rgb[2]);		
41
			$couleur_allouee = imagecolorallocate($image, $couleur_rgb[0], $couleur_rgb[1], $couleur_rgb[2]);		
42
			imagefilledarc($image, $taille/2, $taille/2,
42
			imagefilledarc($image, $taille/2, $taille/2,
43
							$taille, $taille-1, 
43
							$taille, $taille-1, 
44
							$angle, $angle+$pas_angle, 
44
							$angle, $angle+$pas_angle, 
45
							$couleur_allouee, IMG_ARC_PIE);
45
							$couleur_allouee, IMG_ARC_PIE);
46
			$angle = $angle+$pas_angle;
46
			$angle = $angle+$pas_angle;
47
 		}
47
 		}
48
 		
48
 		
49
 		imagefilledarc($image, $taille/2, $taille/2,
49
 		imagefilledarc($image, $taille/2, $taille/2,
50
							$taille, $taille, 
50
							$taille, $taille, 
51
							0, 360, 
51
							0, 360, 
52
							$faux_noir, IMG_ARC_NOFILL);
52
							$faux_noir, IMG_ARC_NOFILL);
53
 		
53
 		
54
 		imagecolortransparent($image, $noir);
54
 		imagecolortransparent($image, $noir);
55
 		
55
 		
56
 		header('Content-type: image/png');
56
 		header('Content-type: image/png');
57
		imagepng($image);
57
		imagepng($image);
58
		imagedestroy($image);
58
		imagedestroy($image);
59
 	} 	
59
 	} 	
60
 	
60
 	
61
 	function html2rgb($color)
61
 	function html2rgb($color)
62
	{
62
	{
63
	    if ($color[0] == '#')
63
	    if ($color[0] == '#')
64
	        $color = substr($color, 1);
64
	        $color = substr($color, 1);
65
	
65
	
66
	    if (strlen($color) == 6)
66
	    if (strlen($color) == 6)
67
	        list($r, $g, $b) = array($color[0].$color[1],
67
	        list($r, $g, $b) = array($color[0].$color[1],
68
	                                 $color[2].$color[3],
68
	                                 $color[2].$color[3],
69
	                                 $color[4].$color[5]);
69
	                                 $color[4].$color[5]);
70
	    elseif (strlen($color) == 3)
70
	    elseif (strlen($color) == 3)
71
	        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
71
	        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
72
	    else
72
	    else
73
	        return false;
73
	        return false;
74
	
74
	
75
	    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
75
	    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
76
	
76
	
77
	    return array($r, $g, $b);
77
	    return array($r, $g, $b);
78
	}
78
	}
79
} 	
79
} 	
80
?>
80
?>