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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
test-GD.php:
<?PHP
class image
{
protected $image;
private $largeur, $hauteur;
private $color = array();
private $bgcolor;
private $t_y;
private $t_x;
private $legende;
public function image()
{
$this->largeur = 200;
$this->hauteur = 200;
$this->image = imagecreate($this->largeur,$this->hauteur);
$this->color = $this->attrib_color();
}
public function tailler($width,$height)
{
$this->largeur = $width;
$this->hauteur = $height;
$this->image = imagecreate($this->largeur,$this->hauteur);
$this->color = $this->attrib_color();
}
private function attrib_color()
{
$this->color[] = imagecolorallocate($this->image,0,192,192);
$this->color[] = imagecolorallocate($this->image,192,50,0);
$this->color[] = imagecolorallocate($this->image,192,192,0);
$this->color[] = imagecolorallocate($this->image,0,192,0);
$this->color[] = imagecolorallocate($this->image,0,0,192);
$this->color[] = imagecolorallocate($this->image,0,192,50);
$this->color[] = imagecolorallocate($this->image,192,0,192);
$this->color[] = imagecolorallocate($this->image,100,50,200);
$this->color[] = imagecolorallocate($this->image,250,50,50);
$this->bgcolor = imagecolorallocate($this->image,255,255,255);
imagefill($this->image,1,1,$this->bgcolor);
}
public function definirDonnee($vals)
{
$this->t_y = $vals;
}
public function definirAbscisse($abs)
{
$this->t_x = $abs;
}
public function definirLegende($leg)
{
$this->legende = $leg;
}
public function dessiner($type)
{
switch($type)
{
case 0:
$this->courbe();
break;
case 1:
$this->histo();
break;
case 2:
$this->secto();
break;
default:
$this->histo();
break;
}
header("Content-Type: image/jpeg");
imagejpeg($this->image);
imagedestroy($this->image);
}
private function histo()
{
$ox = $this->largeur*0.05;
$oy = $this->hauteur*0.05;
$ni = count($this->t_y);
$px = ($this->largeur-2*$ox)/$ni;
$py = ($this->hauteur-2*$oy)/max($this->t_y);
$l = $this->largeur/(3*$ni);
$L = ($this->largeur-$ni*$l)/$ni;
imageline($this->image,$ox,$this->hauteur-$oy,$this->largeur,$this->hauteur-$oy,$this->color[2]);
imageline($this->image,$ox,$this->hauteur-$oy,$ox,$this->hauteur-$this->hauteur,$this->color[2]);
$m = max($this->t_y);
$p = ceil($m*0.1);
for($i=0;$i<=$m*1.1;$i+=$p)
{
imageline($this->image,$ox,$this->hauteur-$i*$py,$ox*3,$this->hauteur-$i*$py,$this->color[4]);
imagestring($this->image,1,$ox-15,$this->hauteur-$i*$py,$i,$this->color[5]);
}
for($i=0;$i<count($this->t_x);$i++)
{
$x1 = $ox+($i*($L+$l));
$y1 = $this->hauteur-($this->t_y[$i]*$py+$oy);
imagefilledrectangle($this->image,$x1,$y1,$x1+$l,$this->hauteur-($oy),$this->color[$i%10]);
imagestring($this->image,1,$x1,$this->hauteur-($oy),$this->t_x[$i],$this->coulour[3]);
}
imagestring($this->image,3,$this->largeur/2,10,$this->legende,$this->color[3]);
}
} |