2 ou 3 classes d'mages en php5 composition d'une équipe de foot

Description

Je viens de me mettre depuis 2 jours à GD et je m'éclate avec ces fonctions:
J'ai créé tous d'abord une classe image simple, puis 3 classes héritées (LOGO, SOCCERGROUND, ET COMPOSITIONGRAPH)
C'est avec cette dernière que je me suis mis à délirer pour mettre à jour la composition d'une equipe de foot sur un terrain (le tout constituant une image dynamique) .
Si vous avez des remarques ou des améliorations je vous écoute.
Je vous livre le tout sans faire le tri.
la classe logo est complétement expérimentale(brouillonne) puisque je découvre mais bon...

Source / Exemple :


<?php

class IMGBASE {
  
  protected $width;
  protected $height;
  protected $bgcolor;     //RESSOURCE COLOR
  protected $pic;         //RESSOURCE IMAGE
  protected $format;
  protected $name;
  protected $extension;
  
  public function __construct ($pwidth=100, $pheight=100, $pR=245, $pG=245, $pB=245, $pformat='image/png'){
    
    $this->width = $pwidth;
    $this->height = $pheight;
    $this->format = $pformat;
    $this->name = 'tmp';
        
      if (!($this->pic = imagecreate ($this->width, $this->height))) 
        throw new Exception ('<font color ="red"><b>EXCEPTION ATTRAPEE :impossible de creer l\'image.</b></font>');
      if (($this->bgcolor = imagecolorallocate ($this->pic, $pR, $pG, $pB))===-1)
        throw new Exception ('<font color ="red"><b>EXCEPTION ATTRAPEE :Impossible d\'allouer une couleur de fond</b></font>');
  }
  
  public function setname ($name){
    $this->name = $name;
    
  }
  
  
  public function display() {
    $this->tofile();
    echo '<img src="'.$this->name.'.'.$this->extension.'">';
  }
  
  public function toscreen(){
    
    if (!$this->pic) throw new Exception ('Impossible d afficher l\'image');
    
    $a=array('image/jpeg'=>'imagejpeg', 'image/png'=>'imagepng', 'image/gif'=>'imagegif');
		$b=$a[$this->format];
		$b($this->pic);
    
  }
  
  public function tofile(){
    
    if (!is_dir(dirname( $this->name))) 
      throw new Exception ('Impossible de créer le fichier '.$this->name.' dans le répertoire '.dirname($this->name));
      
    $a=array('image/jpeg'=>'imagejpeg', 'image/png'=>'imagepng', 'image/gif'=>'imagegif');
		$b=$a[$this->format];
		$b($this->pic,$this->name.'.'.$this->extension);
    
    if ($this->pic)
          imagedestroy($this->pic);

  }  
}
class SOCCERGROUND extends IMGBASE {
    
    protected $scale ;//on multiplie la valeur en pixel par ce nombre pour avoir l'affichage 
    private $lineclr;// COULEUR DE LIGNE
    private $darkgrass;//ID COULEUR DE TONTE
    
    private function colorizegrass(){
      $this->darkgrass = imagecolorallocate ($this->pic, 0, 120, 0);
      for ($i=1 ; $i < 17 ; $i+=2){
        imagefilledrectangle ($this->pic, 0, $i*($this->height/16), $this->width, ($i+1)*($this->height/16), $this->darkgrass); 
      }
    }
    
    public function setscale ($sc){
      $this->scale=$sc;
    }
    
    public function __construct($w=70,$h=105,$sc=5){
      $this->scale = $sc;
      parent::__construct($w*$this->scale, $h*$this->scale, 0, 150, 0, 'image/png');
      $this->lineclr = imagecolorallocate ($this->pic, 255, 255, 255);
    }
    
    private function draw_mediane () {
      imageline($this->pic, 0, $this->height/2, $this->width, $this->height/2, $this->lineclr);
    }
    
    private function draw_medium_circle () {
      imageellipse ($this->pic, $this->width/2, $this->height/2, 18.3*$this->scale, 18.3*$this->scale, $this->lineclr);
      imagefilledellipse(
                  $this->pic,
                  $this->width/2,
                  $this->height/2,
                  5,
                  5,
                  $this->lineclr
                  );
    }
    
    private function draw_gk_zone () {
      $XUpMd = $this->width/2;
      $YUpMd = 0;
      $XDnMd = $this->width/2;
      $YDnMd = $this->height;
      //BUT DU HAUT
      imageline ( 
                $this->pic,
                $XUpMd-((7 * ($this->scale))/2), 
                $YUpMd ,
                $XUpMd-((7 * ($this->scale))/2),
                $YUpMd + 5,
                $this->lineclr
                );
      imageline ( 
                $this->pic,
                $XUpMd+((7 * ($this->scale))/2), 
                $YUpMd ,
                $XUpMd+((7 * ($this->scale))/2),
                $YUpMd + 5,
                $this->lineclr
                );
      //BUT DU BAS
      imageline ( 
                $this->pic,
                $XDnMd-((7 * ($this->scale))/2), 
                $YDnMd ,
                $XDnMd-((7 * ($this->scale))/2),
                $YDnMd - 10,
                $this->lineclr
                );
      imageline ( 
                $this->pic,
                $XDnMd+((7 * ($this->scale))/2), 
                $YDnMd ,
                $XDnMd+((7 * ($this->scale))/2),
                $YDnMd - 10,
                $this->lineclr
                );
      imageline ( 
                $this->pic,
                $XDnMd - ((7 * ($this->scale))/2), 
                $YDnMd - 10,
                $XDnMd + ((7 * ($this->scale))/2),
                $YDnMd - 10,
                $this->lineclr
                );
                
      //PETIT RECTANGLE BUT DU BAS 
      imageline (
                $this->pic,
                $XDnMd - (9 * $this->scale),
                $YDnMd,
                $XDnMd - (9 * $this->scale),
                $YDnMd - (5.5 * $this->scale),
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XDnMd + (9 * $this->scale),
                $YDnMd,
                $XDnMd + (9 * $this->scale),
                $YDnMd - (5.5 * $this->scale),
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XDnMd - (9 * $this->scale),
                $YDnMd - (5.5 * $this->scale),
                $XDnMd + (9 * $this->scale),
                $YDnMd - (5.5 * $this->scale),
                $this->lineclr
                );
                
      //PETIT RECTANGLE BUT DU HAUT
      imageline (
                $this->pic,
                $XUpMd - (9 * $this->scale),
                $YUpMd,
                $XUpMd - (9 * $this->scale),
                $YUpMd + (5.5 * $this->scale),
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XUpMd + (9 * $this->scale),
                $YUpMd,
                $XUpMd + (9 * $this->scale),
                $YUpMd + (5.5 * $this->scale),
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XUpMd - (9 * $this->scale),
                $YUpMd + (5.5 * $this->scale),
                $XUpMd + (9 * $this->scale),
                $YUpMd + (5.5 * $this->scale),
                $this->lineclr
                );
      //POINT PENALTY DU HAUT
      imagefilledellipse(
                  $this->pic,
                  $XUpMd,
                  11 * $this->scale,
                  5,
                  5,
                  $this->lineclr
                  );
      //POINT PENALTY DU BAS
      imagefilledellipse(
                  $this->pic,
                  $XDnMd,
                  $YDnMd-(11 * $this->scale),
                  5,
                  5,
                  $this->lineclr
                  );
      //SURFACE DU HAUT
      imageline (
                $this->pic,
                $XUpMd - (20*$this->scale),
                0,
                $XUpMd - (20*$this->scale),
                16.5 * $this->scale,
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XUpMd + (20*$this->scale),
                0,
                $XUpMd + (20*$this->scale),
                16.5 * $this->scale,
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XUpMd - (20*$this->scale),
                16.5 * $this->scale,
                $XUpMd + (20*$this->scale),
                16.5 * $this->scale,
                $this->lineclr
                );
      //SURFACE DU BAS
      imageline (
                $this->pic,
                $XDnMd - (20*$this->scale),
                $YDnMd,
                $XDnMd - (20*$this->scale),
                $YDnMd - (16.5 * $this->scale),
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XDnMd + (20*$this->scale),
                $YDnMd,
                $XDnMd + (20*$this->scale),
                $YDnMd - (16.5 * $this->scale),
                $this->lineclr
                );
      imageline (
                $this->pic,
                $XDnMd - (20*$this->scale),
                $YDnMd - (16.5 * $this->scale),
                $XDnMd + (20*$this->scale),
                $YDnMd - (16.5 * $this->scale),
                $this->lineclr
                );
      
      //ARC BAS
      imagearc(
                $this->pic,
                $XDnMd,
                $YDnMd-(11 * $this->scale),
                18.3 * $this->scale,
                18.3 * $this->scale,
                180+36.95,
                -36.95,
                $this->lineclr
                );
      //ARC HAUT
      imagearc(
                $this->pic,
                $XUpMd,
                11 * $this->scale,
                18.3 * $this->scale,
                18.3 * $this->scale,
                +36.95,
                180-36.95,
                $this->lineclr
                );
    }
    
    public function rotate($deg){
      $white = imagecolorallocate($this->pic, 255, 255, 255);
      $this->pic = imagerotate($this->pic, $deg, $white);
    }
    
    public function build (){
      $this->colorizegrass();
      $this->draw_mediane();
      $this->draw_medium_circle();
      $this->draw_gk_zone ();
    }

}

class COMPOSITIONGRAPH extends SOCCERGROUND{
  
  private $team = array();
  protected $txtcolor;
  protected $fontsize;
  protected $numcolor; 
  protected $numsize;
  protected $font;
  
  public function __construct($tm=NULL,$psc=5){
    parent::__construct(70,105,$psc);
    if (isset($tm)&&is_array($tm) ){
      $this->team = $tm;
      //echo $tm[0]['poste'];
    }else  throw new Exception('ERREUR DANS LE TABLEAU team');
    $this->txtcolor = imagecolorallocate ($this->pic, 0, 0, 200);
    $this->numcolor = imagecolorallocate ($this->pic, 255, 0, 0);
    $this->fontsize = 3;
    $this->numsize = 4;
  }
  
 /* public function rotate180(){
    $this->pic=imagerotate($this->pic,180,0);
  }*/
  
  public function settxtstyle($R,$G,$B,$sz){
    
    $this->txtcolor = imagecolorallocate ($this->pic, $R, $G, $B);
    $this->fontsize = $sz;
  
  }
  
   public function setnumstyle($R,$G,$B,$sz){
    
    $this->numcolor = imagecolorallocate ($this->pic, $R, $G, $B);
    $this->numsize = $sz;
    
  }
  
  private function incrust_player ( $cx, $cy, $name, $num){
    $textwidth = (strlen($name)*($this->fontsize+4))/2;
    $numwidth = (strlen($num)*($this->numsize+4))/2;
    imagestring(
                $this->pic,
                $this->fontsize,
                $cx - $textwidth,
                $cy,
                $name,
                $this->txtcolor);
    imagestring(
                $this->pic,
                $this->numsize,
                $cx-$numwidth,
                $cy + 12,
                $num,
                $this->numcolor);
  }
  
  protected function writeongraph ($location='UP'){
    if ( (isset($this->team)&& is_array($this->team)) ){
      $n = count ($this->team);
      for( $i=0 ; $i < $n ; $i++){
        switch ($this->team[$i]['poste']){
          case 'GB':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( ($this->width/2), 7*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/2),$this->height-(11*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
                
            }
            break;
          case 'ArCD':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/6), 21*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else $this->incrust_player ( 4*($this->width/6),$this->height-(25*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'ArCG':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 4*($this->width/6), 21*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else $this->incrust_player ( 2*($this->width/6),$this->height-(25*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'ArCC':
           if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( ($this->width/2), 21*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/2), $this->height-(25*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
                
            }
            break;
          case 'ArLD':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( ($this->width/7), 30*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else $this->incrust_player ( 6*($this->width/7), $this->height-(35*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'ArLG':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 6*($this->width/7), 30*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else $this->incrust_player ( ($this->width/7), $this->height-(35*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
                
            }
            break;
          case 'MDC':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/2, 35*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else 
                $this->incrust_player ( $this->width/2, $this->height - (40*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'MDD':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/3, 35*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else 
                $this->incrust_player ( 2*($this->width/3), $this->height - (40*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'MDG':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/3), 35*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/3), $this->height - (40*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'MOD':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/3, 40*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( 2*($this->width/3), $this->height - (50*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'MOG':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/3), 40*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else  
                $this->incrust_player (($this->width/3), $this->height - (50*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'MOC':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/2, 40*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( $this->width/2, $this->height - (50*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'AvD':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/6, 55*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( 5*($this->width/6), $this->height - (60*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'AvG':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 5*($this->width/6), 55*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/6), $this->height - (60*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'AvCD':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/3, 55*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( 2*($this->width/3), $this->height - (60*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'AvCG':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/3), 55*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/3), $this->height - (60*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
          case 'AvCC':
            if ($this->team[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/2, 55*$this->scale, $this->team[$i]['nom'], $this->team[$i]['numero']);
              else
                $this->incrust_player ( $this->width/2, $this->height - (60*$this->scale), $this->team[$i]['nom'], $this->team[$i]['numero']);
            }
            break;
        }
      }
    }
    else throw new Exception ('ERREUR DANS LE TABLEAU team');
  }
   
  public function build($location='UP') {
    parent::build();
    $this->writeongraph($location);
  }
  
}

class GRAPHDOMEXT extends COMPOSITIONGRAPH {
  
  private $teamext;
  private $colorext;
  private $numcolorext;
  
  public function __construct($tabdom, $tabext, $sc=5) {
    parent::__construct($tabdom, $sc);
    $this->teamext=$tabext;
    $this->colorext = imagecolorallocate($this->pic,0,0,120);
    $this->numcolorext = imagecolorallocate($this->pic,120,0,0);
  }
  
  private function incrust_player ( $cx, $cy, $name, $num){
    $textwidth = (strlen($name)*($this->fontsize+4))/2;
    $numwidth = (strlen($num)*($this->numsize+4))/2;
    imagestring(
                $this->pic,
                $this->fontsize,
                $cx - $textwidth,
                $cy,
                $name,
                $this->colorext);
    imagestring(
                $this->pic,
                $this->numsize,
                $cx-$numwidth,
                $cy + 12,
                $num,
                $this->numcolorext);
  }
  
  public function build($location='UP') {
    parent::build();
    $this->writeongraph($location);
    $this->addteamextongraph();
  }
  
  public function addteamextongraph ($location='DOWN'){
    if ( (isset($this->teamext)&& is_array($this->teamext)) ){
      $n = count ($this->teamext);
      for( $i=0 ; $i < $n ; $i++){
        switch ($this->teamext[$i]['poste']){
          case 'GB':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( ($this->width/2), 7*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/2),$this->height-(11*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
                
            }
            break;
          case 'ArCD':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/6), 21*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else $this->incrust_player ( 4*($this->width/6),$this->height-(25*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'ArCG':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 4*($this->width/6), 21*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else $this->incrust_player ( 2*($this->width/6),$this->height-(25*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'ArCC':
           if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( ($this->width/2), 21*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/2), $this->height-(25*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
                
            }
            break;
          case 'ArLD':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( ($this->width/7), 30*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else $this->incrust_player ( 6*($this->width/7), $this->height-(35*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'ArLG':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 6*($this->width/7), 30*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else $this->incrust_player ( ($this->width/7), $this->height-(35*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
                
            }
            break;
          case 'MDC':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/2, 35*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else 
                $this->incrust_player ( $this->width/2, $this->height - (40*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'MDD':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/3, 35*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else 
                $this->incrust_player ( 2*($this->width/3), $this->height - (40*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'MDG':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/3), 35*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/3), $this->height - (40*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'MOD':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/3, 45*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( 2*($this->width/3), $this->height - (45*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'MOG':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/3), 45*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else  
                $this->incrust_player (($this->width/3), $this->height - (45*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
           break;
          case 'MOC':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/2, 45*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( $this->width/2, $this->height - (45*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'AvD':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/6, 55*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( 5*($this->width/6), $this->height - (60*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'AvG':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 5*($this->width/6), 55*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/6), $this->height - (60*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'AvCD':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/3, 55*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( 2*($this->width/3), $this->height - (60*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'AvCG':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( 2*($this->width/3), 55*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( ($this->width/3), $this->height - (60*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
          case 'AvCC':
            if ($this->teamext[$i]['titulaire']){
              if ($location=='UP')
                $this->incrust_player ( $this->width/2, 55*$this->scale, $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
              else
                $this->incrust_player ( $this->width/2, $this->height - (60*$this->scale), $this->teamext[$i]['nom'], $this->teamext[$i]['numero']);
            }
            break;
        }
      }
    }
    else throw new Exception('ERREUR DANS LE TABLEAU teamext');
  }
}

class BASKETGROUND extends IMGBASE{
	
	protected $scale;
	private $lineclr;// COULEUR DE LIGNE
	private $basketclr;

	
	public function __construct($w=15,$h=28,$sc=20){
      
      $this->scale = $sc;
      parent::__construct($w*$this->scale, $h*$this->scale, 228, 202, 152, 'image/png');
      //$this->bgcolor1 = imagecolorallocate ($this->pic ,228,202,152);
      $this->lineclr = imagecolorallocate ($this->pic, 255, 255, 255);
    
    }
  public function rotate ($deg) {
  	$white = imagecolorallocate($this->pic, 255, 255, 255);
    $this->pic = imagerotate($this->pic, $deg, $white);
  }
  public function build() {
  	imageline ($this->pic, 0, $this->height/2, $this->width, $this->height/2, $this->lineclr);
  	imageellipse ($this->pic, $this->width/2, $this->height/2, 3.6*$this->scale, 3.6*$this->scale, $this->lineclr);
  	//DESSIN RAQUETTE HAUT
  	$col = imagecolorallocate($this->pic,100,10,10);
  	imagearc($this->pic, $this->width/2, 1.20*$this->scale, 13*$this->scale, 13*$this->scale, 0, 180, $this->lineclr);
  	imageline ($this->pic, ($this->width/2)-(6.50*$this->scale), 0, ($this->width/2)-(6.50*$this->scale), 1.20*$this->scale, $this->lineclr);
  	imageline ($this->pic, $this->width-(($this->width/2)-(6.50*$this->scale)), 0, $this->width-(($this->width/2)-(6.50*$this->scale)), 1.20*$this->scale, $this->lineclr);
  	imagefilledarc($this->pic, $this->width/2, 5.8*$this->scale, 3.6*$this->scale,3.6*$this->scale, 0, 180,  $col, IMG_ARC_PIE);
  	imageline ($this->pic, ($this->width/2)-(1.8*$this->scale), 5.8*$this->scale, ($this->width/2)+(1.8*$this->scale), 5.8*$this->scale,$this->lineclr);
  	imageline ($this->pic, $this->width/2 - 3*$this->scale,0, $this->width/2 - 1.8*$this->scale, 5.8*$this->scale,$this->lineclr);
  	imageline ($this->pic, $this->width/2 + 3*$this->scale,0, $this->width/2 + 1.8*$this->scale, 5.8*$this->scale,$this->lineclr);
  	
  	//DESSIN RAQUETTE BAS
  	
  	imagearc($this->pic, $this->width/2,$this->height-1.20*$this->scale, 13*$this->scale, 13*$this->scale, 180, 0, $this->lineclr);
  	imageline ($this->pic, ($this->width/2)-(6.50*$this->scale), $this->height, ($this->width/2)-(6.50*$this->scale), $this->height-1.20*$this->scale, $this->lineclr);
  	imageline ($this->pic, $this->width-(($this->width/2)-(6.50*$this->scale)), $this->height, $this->width-(($this->width/2)-(6.50*$this->scale)), $this->height-1.20*$this->scale, $this->lineclr);
  	imagefilledarc($this->pic, $this->width/2, $this->height-5.8*$this->scale, 3.6*$this->scale,3.6*$this->scale, 180, 0, $col, IMG_ARC_PIE);
  	imageline ($this->pic, ($this->width/2)-(1.8*$this->scale), $this->height-5.8*$this->scale, ($this->width/2)+(1.8*$this->scale), $this->height-5.8*$this->scale,$this->lineclr);
  	imageline ($this->pic, $this->width/2 - 3*$this->scale,$this->height, $this->width/2 - 1.8*$this->scale, $this->height-5.8*$this->scale,$this->lineclr);
  	imageline ($this->pic, $this->width/2 + 3*$this->scale,$this->height, $this->width/2 + 1.8*$this->scale, $this->height-5.8*$this->scale,$this->lineclr);
  	
  	
  	imagefilltoborder ($this->pic, $this->width/2, 4*$this->scale,$this->bgcolor,$col);
  	//PANIER HAUT
  	$this->basketclr=imagecolorallocate($this->pic,0 ,0 ,0);
  	imageline ($this->pic, ($this->width/2)-(0.9*$this->scale), 1.2*$this->scale, ($this->width/2)+(0.9*$this->scale), 1.2*$this->scale,$this->basketclr);
  	imageline ($this->pic, $this->width/2, 0, $this->width/2, 1.2*$this->scale, $this->basketclr);
  	imageellipse ($this->pic, $this->width/2, 1.4*$this->scale, 0.4*$this->scale, 0.4*$this->scale, $this->basketclr); 
 		//PANIER HAUT
  	$this->basketclr=imagecolorallocate($this->pic,0 ,0 ,0);
  	imageline ($this->pic, ($this->width/2)-(0.9*$this->scale), $this->height-1.2*$this->scale, ($this->width/2)+(0.9*$this->scale), $this->height-1.2*$this->scale,$this->basketclr);
  	imageline ($this->pic, $this->width/2, $this->height, $this->width/2, $this->height-1.2*$this->scale, $this->basketclr);
  	imageellipse ($this->pic, $this->width/2, $this->height-1.4*$this->scale, 0.4*$this->scale, 0.4*$this->scale, $this->basketclr); 
 		 	
  }
	
}

$joueurs = array (0 => array( 'poste' => 'GB', 
                              'titulaire' => 1, 
                              'numero' => '1', 
                              'nom' => 'COUPET'),
                  1 => array( 'poste' => 'ArCD',
                              'titulaire' => 1, 
                              'numero' => '2', 
                              'nom' => 'THURAM'),
                  2 => array( 'poste' => 'ArCG',
                              'titulaire' => 1, 
                              'numero' => '5', 
                              'nom' => 'GALLAS'),
                  3 => array( 'poste' => 'ArLD',
                              'titulaire' => 1, 
                              'numero' => '15', 
                              'nom' => 'SAGNOL'),
                  4 => array( 'poste' => 'ArLG',
                              'titulaire' => 1, 
                              'numero' => '14', 
                              'nom' => 'REVEILLERE'),
                  5 => array( 'poste' => 'MDC',
                              'titulaire' => 1, 
                              'numero' => '4', 
                              'nom' => 'VIEIRA'),
                  6 => array( 'poste' => 'MOD',
                              'titulaire' => 1, 
                              'numero' => '6', 
                              'nom' => 'MAKELELE'),
                  7 => array( 'poste' => 'MOG',
                              'titulaire' => 1, 
                              'numero' => '10', 
                              'nom' => 'ZIDANE'),
                  8 => array( 'poste' => 'AvD',
                              'titulaire' => 1, 
                              'numero' => '8', 
                              'nom' => 'GIULY'),
                  9 => array( 'poste' => 'AvG',
                              'titulaire' => 1, 
                              'numero' => '12', 
                              'nom' => 'HENRY'),
                  10 => array( 'poste' => 'AvCC',
                              'titulaire' => 1, 
                              'numero' => '20', 
                              'nom' => 'TREZEGUET')                                                                                          
                  ); 
                  
$adversaires = array (
                  0 => array( 'poste' => 'GB', 
                              'titulaire' => 1, 
                              'numero' => '16', 
                              'nom' => 'BARTHEZ'),
                  1 => array( 'poste' => 'ArCD',
                              'titulaire' => 1, 
                              'numero' => '21', 
                              'nom' => 'BOUMSONG'),
                  2 => array( 'poste' => 'ArCC',
                              'titulaire' => 1, 
                              'numero' => '18', 
                              'nom' => 'MEXES'),
                  3 => array( 'poste' => 'ArLD',
                              'titulaire' => 1, 
                              'numero' => '19', 
                              'nom' => 'EVRA'),
                  4 => array( 'poste' => 'ArCG',
                              'titulaire' => 1, 
                              'numero' => '17', 
                              'nom' => 'MONTSOREAU'),
                  5 => array( 'poste' => 'MDC',
                              'titulaire' => 1, 
                              'numero' => '26', 
                              'nom' => 'DIARRA'),
                  6 => array( 'poste' => 'MOD',
                              'titulaire' => 1, 
                              'numero' => '7', 
                              'nom' => 'DHORASSO'),
                  7 => array( 'poste' => 'MOG',
                              'titulaire' => 1, 
                              'numero' => '22', 
                              'nom' => 'MICOUD'),
                  8 => array( 'poste' => 'AvCD',
                              'titulaire' => 1, 
                              'numero' => '13', 
                              'nom' => 'WILTORD'),
                  9 => array( 'poste' => 'ArLG',
                              'titulaire' => 1, 
                              'numero' => '23', 
                              'nom' => 'MALOUDA'),
                  10 => array( 'poste' => 'AvCG',
                              'titulaire' => 1, 
                              'numero' => '9', 
                              'nom' => 'SAHA')                                                                                          
                  ); 
 

try {
  $terrain = new SOCCERGROUND(55,95,4);
  $terrain->setname('images/terrain');
  $terrain->build();
  $terrain->display();
  echo ' ';
  $terrainmini = new SOCCERGROUND(45,90,4);
  $terrainmini->setname('images/mini');
  $terrainmini->build();
  $terrainmini->display();
  echo ' ';
  //echo ('<br>');
  $ext=new GRAPHDOMEXT ($joueurs,$adversaires,5);
  $ext->settxtstyle (200,200,200,3);
  $ext->setnumstyle (0,0,100,3);
  $ext->build();
  $ext->display();
  //echo ('<br>');
  $terrainmaxi = new SOCCERGROUND(90,120,4);
  $terrainmaxi->setname('images/maxi');
  $terrainmaxi->build();
  
  $terrainmaxi->rotate(90);
  $terrainmaxi->display();
  $test = new BASKETGROUND(15,28,20);
  $test -> setname('images/tmp');
  $test->build();
  $test->rotate(90);
  //header ('Content-Type : image/png');
  //$test->toscreen();
  $test->display();
}
catch(Exception $e){
  echo ($e->getMessage());
}

?>

Conclusion :


Ces classes sans prétentions peuvent être utiles aux webmasters et développeurs de sites dédiés au sport.

On peut gérer l'echelle du terrain en passant dans le constructeur l'echelle (scale) en parametre lors de l'appel avec new.
Voir exemple en bas du script (5 par défaut = multiplie les dimensions par 5).
Les terrains sont dessinés suivant les normes officielles des fédérations internationales.

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.