begin process at 2012 05 27 19:04:30
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Graphique

 > LIBRAIRIE GRAPHIQUE POUR GÉRER UN DESSIN AVEC FORMES (PHP5, CLASSE, HÉRITAGE, POLYMORPHISME)

LIBRAIRIE GRAPHIQUE POUR GÉRER UN DESSIN AVEC FORMES (PHP5, CLASSE, HÉRITAGE, POLYMORPHISME)


 Information sur la source

Note :
7,83 / 10 - par 6 personnes
7,83 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Graphique Niveau :Expert Date de création :16/06/2004 Vu / téléchargé :5 575 / 270

Auteur : GRenard

Ecrire un message privé
Site perso
Commentaire sur cette source (9)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
Voici un code qui permet de gérer facilement des formes sur un dessin. Le rendu est peut-etre basique, mais vous pouvez regarder le contenu du code. Il contient des classes avec des héritages ainsi que du polymorphisme écrit en php5.
Son utilisation peut-etre utile pour de la génération automatique d'image... à vous de voir.
Vous pouvez aussi essayer d'apprendre avec ce code ;)

Source

  • <?php
  • //////////////////////////////////////////////////////////////////////
  • // FDraw.php
  • //--------------------------------------------------------------------
  • //
  • // Classes for Drawing Objects
  • //
  • //--------------------------------------------------------------------
  • // Revision History
  • // V1.00 16 jun 2004 Jean-Sebastien Goupil
  • //--------------------------------------------------------------------
  • // (c) Jean-Sebastien Goupil
  • // http://www.lookstrike.com
  • //--------------------------------------------------------------------
  • //////////////////////////////////////////////////////////////////////
  • define("DEBUG",0);
  • define("IMG_FORMAT_PNG", 1);
  • define("IMG_FORMAT_JPEG", 2);
  • define("IMG_FORMAT_WBMP", 4);
  • define("IMG_FORMAT_GIF", 8);
  • //////////////////////////////////////////////////////////////////////
  • // Function: DebugTool()
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: If DEBUG == 1, this will print the argument
  • // $text when calling the function.
  • //
  • //////////////////////////////////////////////////////////////////////
  • function DebugTool($text) {
  • if(constant("DEBUG")==1) {
  • echo $text."<br>\n";
  • }
  • }
  • //////////////////////////////////////////////////////////////////////
  • // Class: FColor
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Holds Color in RGB Format.
  • //
  • // Function FColor(): Save RGB value into the classes
  • // Function allocate(): Return the int value for PHP color
  • // Function r(): Return Red Color
  • // Function g(): Return Green Color
  • // Function b(): Return Blue Color
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FColor {
  • protected $r,$g,$b; // int Hexadecimal Value
  • public function FColor($r,$g,$b){
  • $this->r = $r;
  • $this->g = $g;
  • $this->b = $b;
  • DebugTool("*** FColor Created");
  • }
  • public function r(){
  • return $this->r;
  • }
  • public function g(){
  • return $this->g;
  • }
  • public function b(){
  • return $this->b;
  • }
  • public function allocate($im) {
  • DebugTool("* Color ".$this->r.".".$this->g.".".$this->b);
  • return imagecolorallocate($im,$this->r,$this->g,$this->b);
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FPoint
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Holds Position of object in 2d-Space.
  • //
  • // Function FPoint(): Save Position (x,y)
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FPoint {
  • protected $x, $y; // int
  • public function FPoint($x,$y){
  • $this->x = $x;
  • $this->y = $y;
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: Form
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Abstract Class, holds all forms that can be
  • // drawn in PHP.
  • //
  • // Function Form(): Save Position (x,y), Color (color1,color2)
  • // Function x(): Return X Position
  • // Function y(): Return Y Position
  • // Function w(): Return Width (if existing)
  • // Function h(): Return Height (if existing)
  • // Function draw(): Polymorphism
  • // By calling this function, you draw the right
  • // form held into Form Class.
  • //
  • //////////////////////////////////////////////////////////////////////
  • class Form extends FPoint {
  • protected $color1, $color2; // Fcolor
  • public function Form($x,$y,Fcolor $color1,Fcolor $color2) {
  • FPoint::FPoint($x,$y);
  • $this->color1 = $color1;
  • $this->color2 = $color2;
  • DebugTool("*** Form Created");
  • }
  • public function x() {
  • return $this->x;
  • }
  • public function y() {
  • return $this->y;
  • }
  • public function w() {
  • return $this->w;
  • }
  • public function h() {
  • return $this->h;
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FRectangle
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Rectangle Object
  • // * color1 and color2 aren't null
  • // Border (color1), Filled (color2)
  • // * color1 null, color2 not null
  • // Border (none), Filled (color2)
  • // * color1 not null, color2 null
  • // Border (color1), Filled (none)
  • //
  • // Function FRectangle():Save Position (x,y), Size (w,h), Color (color1,color2)
  • // Function draw(): Draw Rectangle on $im
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FRectangle extends Form {
  • protected $w, $h; // int
  • public function FRectangle($x,$y,$w,$h,Fcolor $color1,Fcolor $color2) {
  • Form::Form($x,$y,$color1,$color2);
  • $this->w = $w;
  • $this->h = $h;
  • DebugTool("*** FRectangle Created");
  • }
  • public function draw($im) {
  • $color_foreground = (is_null($this->color1))?NULL:$this->color1->allocate($im);
  • $color_background = (is_null($this->color2))?NULL:$this->color2->allocate($im);
  • if(!is_null($color_background))
  • imagefilledrectangle($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,$color_background);
  • if(!is_null($color_foreground))
  • imagerectangle($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,$color_foreground);
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FSquare
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Child of FRectangle. Same Explanation and Functions.
  • // Size (c) -> Side
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FSquare extends FRectangle {
  • public function FSquare($x,$y,$c,Fcolor $color1,Fcolor $color2) {
  • FRectangle::FRectangle($x,$y,$c,$c,$color1,$color2);
  • DebugTool("*** FSquare Created");
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FEllipse
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Ellipse Object
  • // * color1 and color2 aren't null
  • // Border (color1), Filled (color2)
  • // * color1 null, color2 not null
  • // Border (none), Filled (color2)
  • // * color1 not null, color2 null
  • // Border (color1), Filled (none)
  • //
  • // Function FEllipse(): Save Position (x,y), Size (w,h), Color (color1,color2)
  • // Function draw(): Draw Ellipse on $im
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FEllipse extends Form {
  • protected $w, $h; // int
  • public function FEllipse($x,$y,$w,$h,Fcolor $color1,Fcolor $color2) {
  • Form::Form($x,$y,$color1,$color2);
  • $this->w = $w;
  • $this->h = $h;
  • DebugTool("*** FEllipse Created");
  • }
  • public function draw($im) {
  • $color_foreground = (is_null($this->color1))?NULL:$this->color1->allocate($im);
  • $color_background = (is_null($this->color2))?NULL:$this->color2->allocate($im);
  • if(!is_null($color_background))
  • imagefilledellipse($im,$this->x,$this->y,$this->w,$this->h,$color_background);
  • if(!is_null($color_foreground))
  • imageellipse($im,$this->x,$this->y,$this->w,$this->h,$color_foreground);
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FCircle
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Child of FEllipse. Same Explanation and Functions.
  • // Size (r) -> Radius
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FCircle extends FEllipse {
  • public function FCircle($x,$y,$r,FColor $color1,FColor $color2) {
  • FEllipse::FEllipse($x,$y,$r,$r,$color1,$color2);
  • DebugTool("*** FCircle Created");
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FVector
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Vector Object (Line)
  • // * color1 and color2 aren't null
  • // Dashed Line of color1 and color2
  • // * color1 not null, color2 null
  • // Continuous Line
  • //
  • // Function FVector(): Save Position (x,y), Size (w,h), Color (color1,color2)
  • // Function draw(): Draw Vector on $im
  • //
  • // ** WARNING **
  • // w and h is the width and height of the line, x and y being start point
  • // The x2, and y2 are respectively x+w and y+h
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FVector extends Form { // a vector is a flatten form
  • protected $w, $h; // int
  • public function fVector($x,$y,$w,$h,Fcolor $color1,Fcolor $color2) {
  • Form::Form($x,$y,$color1,$color2);
  • $this->w = $w;
  • $this->h = $h;
  • DebugTool("*** FVector Created");
  • }
  • public function draw($im) {
  • $color1 = (is_null($this->color1))?NULL:$this->color1->allocate($im);
  • $color2 = (is_null($this->color2))?NULL:$this->color2->allocate($im);
  • if(!is_null($color1) && !is_null($color2)){
  • $style = array($color1,$color1,$color1,$color1,$color1,$color2,$color2,$color2,$color2,$color2);
  • imagesetstyle($im, $style);
  • imageline($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,IMG_COLOR_STYLED);
  • }
  • elseif(!is_null($color1))
  • imageline($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,$color1);
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FText
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Holds Text
  • // * font: int 1 to 5 (inclusively)
  • // * horiz: boolean (true=horizontal, false=vertical)
  • //
  • // Function FText(): Save Position (x,y), Text (text), Font (font), Direction (horiz), Color (color)
  • // Function draw(): Draw Text on $im
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FText extends FPoint {
  • private $text; // char *
  • private $color; // Fcolor
  • private $font; // int
  • private $horiz; // bool
  • public function FText($x,$y,$text,$font,$horiz,FColor $color){
  • FPoint::FPoint($x,$y);
  • $this->text = $text;
  • $this->color = $color;
  • $this->font = $font;
  • $this->horiz = $horiz;
  • DebugTool("*** FText Created");
  • }
  • public function draw($im) {
  • $color = (is_null($this->color))?NULL:$this->color->allocate($im);
  • if(!is_null($color))
  • if($this->horiz==true)
  • imagestring($im,$this->font,$this->x,$this->y,$this->text,$color);
  • else
  • imagestringup($im,$this->font,$this->x,$this->y,$this->text,$color);
  • }
  • };
  • //////////////////////////////////////////////////////////////////////
  • // Class: FDrawing
  • //////////////////////////////////////////////////////////////////////
  • //
  • // Explanation: Holds the drawing $im and can also holds all forms and texts
  • // * You must call init().
  • // * You can use get_im() to add other kind of form not
  • // held into these classes.
  • //
  • // Function FDrawing(): Size (w,h), Filename (filename), BackGround Color (color)
  • // Function init(): Init Image and color background
  • // Function get_im(): Return $im
  • // Function add_form(): Add form into the form array (for future drawing)
  • // Function add_text(): Add text into the text array (for future drawing)
  • // Function draw_all(): Draw first all forms and after all texts on $im
  • // Function finish(): Save $im into the file (many format available)
  • // Function destroy(): Free the memory of PHP (called also by destructor)
  • //
  • //////////////////////////////////////////////////////////////////////
  • class FDrawing {
  • private $w, $h; // int
  • private $color; // Fcolor
  • private $filename; // char *
  • private $im; // {object}
  • private $form = array();// Form *
  • private $text = array();// Ftext *
  • public function FDrawing($w,$h,$filename,Fcolor $color) {
  • $this->w = $w;
  • $this->h = $h;
  • $this->filename = $filename;
  • $this->color = $color;
  • DebugTool("*** FDrawing Created");
  • }
  • function __destruct() {
  • $this->destroy();
  • }
  • public function init(){
  • $this->im = imagecreate($this->w, $this->h)
  • or die("Can't Initialize the GD Libraty");
  • imagecolorallocate($this->im,$this->color->r(),$this->color->g(),$this->color->b());
  • }
  • public function get_im(){
  • return $this->im;
  • }
  • public function add_form(Form $form){
  • $this->form[] = $form;
  • }
  • public function add_text(Ftext $text){
  • $this->text[] = $text;
  • }
  • public function draw_all(){
  • for($i=0;$i<count($this->form);$i++)
  • $this->form[$i]->draw($this->im);
  • for($i=0;$i<count($this->text);$i++)
  • $this->text[$i]->draw($this->im);
  • }
  • public function finish($image_style=IMG_FORMAT_PNG,$quality=100){
  • if($image_style==constant("IMG_FORMAT_PNG"))
  • imagepng($this->im,$this->filename);
  • elseif($image_style==constant("IMG_FORMAT_JPEG"))
  • imagejpeg($this->im,$this->filename,$quality);
  • elseif($image_style==constant("IMG_FORMAT_WBMP"))
  • imagewbmp($this->im,$this->filename);
  • elseif($image_style==constant("IMG_FORMAT_GIF"))
  • imagegif($this->im,$this->filename);
  • }
  • public function destroy(){
  • imagedestroy($this->im);
  • }
  • };
  • ?>
<?php
//////////////////////////////////////////////////////////////////////
// FDraw.php
//--------------------------------------------------------------------
//
// Classes for Drawing Objects
//
//--------------------------------------------------------------------
// Revision History
// V1.00	16 jun	2004	Jean-Sebastien Goupil
//--------------------------------------------------------------------
// (c) Jean-Sebastien Goupil
// http://www.lookstrike.com
//--------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////

define("DEBUG",0);
define("IMG_FORMAT_PNG",	1);
define("IMG_FORMAT_JPEG",	2);
define("IMG_FORMAT_WBMP",	4);
define("IMG_FORMAT_GIF",	8);

//////////////////////////////////////////////////////////////////////
// Function: DebugTool()
//////////////////////////////////////////////////////////////////////
//
// Explanation:		If DEBUG == 1, this will print the argument
//			$text when calling the function.
//
//////////////////////////////////////////////////////////////////////
function DebugTool($text) {
	if(constant("DEBUG")==1) {
		echo $text."<br>\n";
	}
}

//////////////////////////////////////////////////////////////////////
// Class: FColor
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Holds Color in RGB Format.
//
// Function FColor():	Save RGB value into the classes
// Function allocate():	Return the int value for PHP color
// Function r():	Return Red Color
// Function g():	Return Green Color
// Function b():	Return Blue Color
//
//////////////////////////////////////////////////////////////////////
class FColor {
	protected $r,$g,$b;	// int Hexadecimal Value

	public function FColor($r,$g,$b){
		$this->r = $r;
		$this->g = $g;
		$this->b = $b;
		DebugTool("*** FColor Created");
	}
	public function r(){
		return $this->r;
	}
	public function g(){
		return $this->g;
	}
	public function b(){
		return $this->b;
	}
	public function allocate($im) {
		DebugTool("* Color ".$this->r.".".$this->g.".".$this->b);
		return imagecolorallocate($im,$this->r,$this->g,$this->b);
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FPoint
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Holds Position of object in 2d-Space.
//
// Function FPoint():	Save Position (x,y)
//
//////////////////////////////////////////////////////////////////////
class FPoint {
	protected $x, $y;	// int

	public function FPoint($x,$y){
		$this->x = $x;
		$this->y = $y;
	}
};


//////////////////////////////////////////////////////////////////////
// Class: Form
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Abstract Class, holds all forms that can be
//			drawn in PHP.
//
// Function Form():	Save Position (x,y), Color (color1,color2)
// Function x():	Return X Position
// Function y():	Return Y Position
// Function w():	Return Width (if existing)
// Function h():	Return Height (if existing)
// Function draw():	Polymorphism
//			By calling this function, you draw the right
//			form held into Form Class.
// 
//////////////////////////////////////////////////////////////////////
class Form extends FPoint {
	protected $color1, $color2;	// Fcolor

        public function Form($x,$y,Fcolor $color1,Fcolor $color2) {
		FPoint::FPoint($x,$y);
		$this->color1 = $color1;
		$this->color2 = $color2;
		DebugTool("*** Form Created");
	}
	public function x() {
		return $this->x;
	}
	public function y() {
		return $this->y;
	}
	public function w() {
		return $this->w;
	}
	public function h() {
		return $this->h;
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FRectangle
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Rectangle Object
//			 * color1 and color2 aren't null
//			   Border (color1), Filled (color2)
//			 * color1 null, color2 not null
//			   Border (none), Filled (color2)
//			 * color1 not null, color2 null
//			   Border (color1), Filled (none)
//
// Function FRectangle():Save Position (x,y), Size (w,h), Color (color1,color2)
// Function draw():	Draw Rectangle on $im
//
//////////////////////////////////////////////////////////////////////
class FRectangle extends Form {
	protected $w, $h;	// int

	public function FRectangle($x,$y,$w,$h,Fcolor $color1,Fcolor $color2) {
		Form::Form($x,$y,$color1,$color2);
		$this->w = $w;
		$this->h = $h;
		DebugTool("*** FRectangle Created");
	}
	public function draw($im) {
		$color_foreground = (is_null($this->color1))?NULL:$this->color1->allocate($im);
		$color_background = (is_null($this->color2))?NULL:$this->color2->allocate($im);
		if(!is_null($color_background))
			imagefilledrectangle($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,$color_background);
		if(!is_null($color_foreground))
			imagerectangle($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,$color_foreground);
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FSquare
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Child of FRectangle. Same Explanation and Functions.
//			Size (c) -> Side
//
//////////////////////////////////////////////////////////////////////
class FSquare extends FRectangle {
	public function FSquare($x,$y,$c,Fcolor $color1,Fcolor $color2) {
		FRectangle::FRectangle($x,$y,$c,$c,$color1,$color2);
		DebugTool("*** FSquare Created");
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FEllipse
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Ellipse Object
//			 * color1 and color2 aren't null
//			   Border (color1), Filled (color2)
//			 * color1 null, color2 not null
//			   Border (none), Filled (color2)
//			 * color1 not null, color2 null
//			   Border (color1), Filled (none)
//
// Function FEllipse():	Save Position (x,y), Size (w,h), Color (color1,color2)
// Function draw():	Draw Ellipse on $im
//
//////////////////////////////////////////////////////////////////////
class FEllipse extends Form {
	protected $w, $h;	// int

	public function FEllipse($x,$y,$w,$h,Fcolor $color1,Fcolor $color2) {
		Form::Form($x,$y,$color1,$color2);
		$this->w = $w;
		$this->h = $h;
		DebugTool("*** FEllipse Created");
	}
	public function draw($im) {
		$color_foreground = (is_null($this->color1))?NULL:$this->color1->allocate($im);
		$color_background = (is_null($this->color2))?NULL:$this->color2->allocate($im);
		if(!is_null($color_background))
			imagefilledellipse($im,$this->x,$this->y,$this->w,$this->h,$color_background);
		if(!is_null($color_foreground))
			imageellipse($im,$this->x,$this->y,$this->w,$this->h,$color_foreground);
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FCircle
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Child of FEllipse. Same Explanation and Functions.
//			Size (r) -> Radius
//
//////////////////////////////////////////////////////////////////////
class FCircle extends FEllipse {
	public function FCircle($x,$y,$r,FColor $color1,FColor $color2) {
		FEllipse::FEllipse($x,$y,$r,$r,$color1,$color2);
		DebugTool("*** FCircle Created");
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FVector
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Vector Object (Line)
//			 * color1 and color2 aren't null
//			   Dashed Line of color1 and color2
//			 * color1 not null, color2 null
//			   Continuous Line
//
// Function FVector():	Save Position (x,y), Size (w,h), Color (color1,color2)
// Function draw():	Draw Vector on $im
//
// ** WARNING **
// w and h is the width and height of the line, x and y being start point
// The x2, and y2 are respectively x+w and y+h
//
//////////////////////////////////////////////////////////////////////
class FVector extends Form { // a vector is a flatten form
	protected $w, $h;	// int

	public function fVector($x,$y,$w,$h,Fcolor $color1,Fcolor $color2) {
		Form::Form($x,$y,$color1,$color2);
		$this->w = $w;
		$this->h = $h;
		DebugTool("*** FVector Created");
	}
	public function draw($im) {
		$color1 = (is_null($this->color1))?NULL:$this->color1->allocate($im);
		$color2 = (is_null($this->color2))?NULL:$this->color2->allocate($im);
		if(!is_null($color1) && !is_null($color2)){
			$style = array($color1,$color1,$color1,$color1,$color1,$color2,$color2,$color2,$color2,$color2);
			imagesetstyle($im, $style);
			imageline($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,IMG_COLOR_STYLED);
		}
		elseif(!is_null($color1))
			imageline($im,$this->x,$this->y,$this->x+$this->w,$this->y+$this->h,$color1);
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FText
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Holds Text
//			 * font: int 1 to 5 (inclusively)
//			 * horiz: boolean (true=horizontal, false=vertical)
//
// Function FText():	Save Position (x,y), Text (text), Font (font), Direction (horiz), Color (color)
// Function draw():	Draw Text on $im
//
//////////////////////////////////////////////////////////////////////
class FText extends FPoint {
	private $text;		// char *
	private $color;		// Fcolor
	private $font;		// int
	private $horiz;		// bool

	public function FText($x,$y,$text,$font,$horiz,FColor $color){
		FPoint::FPoint($x,$y);
		$this->text = $text;
		$this->color = $color;
		$this->font = $font;
		$this->horiz = $horiz;
		DebugTool("*** FText Created");
	}
	public function draw($im) {
		$color = (is_null($this->color))?NULL:$this->color->allocate($im);
		if(!is_null($color))
			if($this->horiz==true)
				imagestring($im,$this->font,$this->x,$this->y,$this->text,$color);
			else
				imagestringup($im,$this->font,$this->x,$this->y,$this->text,$color);
	}
};

//////////////////////////////////////////////////////////////////////
// Class: FDrawing
//////////////////////////////////////////////////////////////////////
//
// Explanation:		Holds the drawing $im and can also holds all forms and texts
//			* You must call init().
//			* You can use get_im() to add other kind of form not
//			  held into these classes.
//
// Function FDrawing():	Size (w,h), Filename (filename), BackGround Color (color)
// Function init():	Init Image and color background
// Function get_im():	Return $im
// Function add_form():	Add form into the form array (for future drawing)
// Function add_text(): Add text into the text array (for future drawing)
// Function draw_all():	Draw first all forms and after all texts on $im
// Function finish():	Save $im into the file (many format available)
// Function destroy():	Free the memory of PHP (called also by destructor)
//
//////////////////////////////////////////////////////////////////////
class FDrawing {
	private $w, $h;		// int
	private $color;		// Fcolor
	private $filename;	// char *
	private $im;		// {object}
	private $form = array();// Form *
	private $text = array();// Ftext *

	public function FDrawing($w,$h,$filename,Fcolor $color) {
		$this->w = $w;
		$this->h = $h;
		$this->filename = $filename;
		$this->color = $color;
		DebugTool("*** FDrawing Created");
	}
	function __destruct() {
		$this->destroy();
	}
	public function init(){
		$this->im = imagecreate($this->w, $this->h)
		or die("Can't Initialize the GD Libraty");
		imagecolorallocate($this->im,$this->color->r(),$this->color->g(),$this->color->b());
	}
	public function get_im(){
		return $this->im;
	}
	public function add_form(Form $form){
		$this->form[] = $form;
	}
	public function add_text(Ftext $text){
		$this->text[] = $text;
	}
	public function draw_all(){
		for($i=0;$i<count($this->form);$i++)
			$this->form[$i]->draw($this->im);
		for($i=0;$i<count($this->text);$i++)
			$this->text[$i]->draw($this->im);
	}
	public function finish($image_style=IMG_FORMAT_PNG,$quality=100){
		if($image_style==constant("IMG_FORMAT_PNG"))
			imagepng($this->im,$this->filename);
		elseif($image_style==constant("IMG_FORMAT_JPEG"))
			imagejpeg($this->im,$this->filename,$quality);
		elseif($image_style==constant("IMG_FORMAT_WBMP"))
			imagewbmp($this->im,$this->filename);
		elseif($image_style==constant("IMG_FORMAT_GIF"))
			imagegif($this->im,$this->filename);
	}
	public function destroy(){
		imagedestroy($this->im);
	}
};
?>

 Conclusion

Pour ceux qui veulent modifier le code, libre à vous... Il serait bien de m'en avertir et me dire quelle modification vous faites ou vous avez fait pour en faire profiter à tout le monde.

Désolé pour ceux qui n'aiment pas l'anglais, mais je code toujours en anglais maintenant... c'est plus portable entre programmeur :P

Et peut-etre un petit coup de gueule à passer, j'ai codé le plus propre possible et je vous conseille d'en faire AUTANT !
(register_global=Off, short_open_tag=Off, ...) tout ce genre de configurations !

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture LECTURE/ÉCRITURE DE TAGS ID3 VERSION 1 ET VERSION 2
Source avec Zip GÉRER LES ÉCHAPPEMENTS DE CARACTÈRES SUR TABLEAUX MULTIDIMEN...
Source avec Zip Source avec une capture PROJECT SELECTOR (SÉLECTION FACILE DE PROJET AVEC APACHE) ET...
Source avec Zip Source avec une capture STATISTIQUES DE VOTRE PROJET (NOMBRE DE DOSSIERS, FICHIERS, ...
Source avec Zip Source avec une capture AFFICHAGE TABLEAU AVEC TEMPLATE CLASSE

 Sources de la même categorie

Source avec Zip Source avec une capture CAMEMBERT BD par dardelphi
Source avec une capture AMÉLIORATION : CAMEMBERT par asphator
GESTION DE COULEUR par manuche
Source avec Zip NAVIGATOR (+CSSDETECTOR) par xXVoxPopuliXx
COMMENT, AVEC GD, DESSINER UN RECTANGLE TRANSPARENT PLEIN AV... par Rainbow

Commentaires et avis

Commentaire de GRenard le 16/06/2004 10:11:26

Laissez vos commentaires :)

Commentaire de Gorrk le 17/06/2004 10:15:24

Tres bonne source, tres propre.

Commentaire de Mechanicman le 17/06/2004 20:11:36

...argl....encore des maths....mais comme c'est cool j'te met 9....en meme temps j'suis une grosse quiche en maths alors l'interet de ce script j'vois pas trop ;)

Commentaire de GRenard le 17/06/2004 20:21:03

Pas full de maths dans celui la ! ca permet de faire des dessins basic... comme moi jme sert de ca pour dessiner un arbre de tournois (1 vs 1 et la celui qui gagne monte ...) CA c'est des maths :P mais la, c'est plutot basic :) ca démontre l'utilisation de php5 et classes polymorphiques avec héritage

Commentaire de babid le 17/12/2004 15:49:34

Salut GRenard,

Excelente ta source, comme d'hab ;)
Je voulais te demander quelques choses à toi particulièrement, mais qui pourra servir à beaucoup d'entre nous. Ou peut-on trouver de la doc (en français), sur le nouvelles fonctionnalités de php5 et des class en particulier.

Je te remercie d'avance pour la réponse.

PS: je te mets 9/10 à ta source.
Bonne continuation.

Commentaire de GRenard le 17/12/2004 16:13:51

Sur php.net encore tout peut être trouvé :

Chapitre 18. Les classes et les objets (PHP 5)
http://ca.php.net/manual/fr/language.oop5.php

Merci pour ton commentaire.

Commentaire de babid le 17/12/2004 16:46:43

Je te remercie grandement.

A bientôt

Commentaire de mtaveau le 25/01/2007 20:57:48

Quand je lance le code, j'ai une erreur. je n'arrive à le faire marcher.

D'autre part si vous pouviez mettre votre code php en ligne, ce serait pratique, on pourrait voir ce qu'il fait.

Commentaire de GRenard le 25/01/2007 21:33:51

Tu dois avoir PHP5

Le code fait comme le screenshot avec index.php

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,406 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales