Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 501 Rev 506
1
<?php
1
<?php
2
 
2
 
3
/**
3
/**
4
* Classe CommunGraphiques.php regroupement de fonctions pour les graphiques
4
* Classe CommunGraphiques.php regroupement de fonctions pour les graphiques
5
*  graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
5
*  graphiques/#typegraphique/#bdnt.nn:#num_nomen --> renvoie un graphique avec les données connues
6
*   
6
*   
7
*
7
*
8
* @package eflore-projets
8
* @package eflore-projets
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
9
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
10
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
10
* @author Mathilde SALTHUN-LASSALLE <mathilde@tela-botanica.org>
11
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
11
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
12
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
12
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
13
* @version 1.0
13
* @version 1.0
14
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
14
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
15
*/
15
*/
16
 
16
 
17
abstract class CommunGraphiques extends Commun{
17
abstract class CommunGraphiques extends Commun{
18
	
18
	
19
	protected $parametres = array();
19
	protected $parametres = array();
20
	protected $ressources = array();
20
	protected $ressources = array();
21
	
21
	
22
	protected $Bdd;
22
	protected $Bdd;
23
	protected $config;
23
	protected $config;
24
	protected $cache;
24
	protected $cache;
25
	protected $metadonnees;
25
	protected $metadonnees;
26
	protected $version;
26
	protected $version;
27
	protected $serviceNom = 'Graphiques';
27
	protected $serviceNom = 'Graphiques';
28
	
28
	
29
	protected $graduations_id = array();
29
	protected $graduations_id = array();
30
	protected  $champs_ontologiques =  array();
30
	protected  $champs_ontologiques =  array();
31
	protected $nomGraphique = array();
31
	protected $nomGraphique = array();
32
	
32
	
33
	protected $table = '';
33
	protected $table = '';
34
	protected $requete_condition = "";
34
	protected $requete_condition = "";
35
	protected $requete_champs;
35
	protected $requete_champs;
36
	
36
	
37
	protected $convertisseur;
37
	protected $convertisseur;
38
	protected $cheminGraphBase;
38
	protected $cheminGraphBase;
39
	protected $valeurs_en_pourcentage = array();
39
	protected $valeurs_en_pourcentage = array();
40
	protected $dom;
40
	protected $dom;
41
	protected $largeurSVG = "500";
41
	protected $largeurSVG = "500";
42
	protected $valeurs_champs;
42
	protected $valeurs_champs;
43
	
43
	
44
	
44
	
45
	public function consulter($ressources, $parametres) {
45
	public function consulter($ressources, $parametres) {
46
		$this->ressources = $ressources;
46
		$this->ressources = $ressources;
47
		$this->parametres = $parametres;
47
		$this->parametres = $parametres;
-
 
48
		$this->verifierParametres();
48
		$this->initialiserConfiguration();
49
		$this->initialiserConfiguration();
49
		$resultats = '';
50
		$resultats = '';
50
		$this->traiterRessources();
51
		$this->traiterRessources();
51
		$requete = $this->assemblerLaRequete();
52
		$requete = $this->assemblerLaRequete();
52
		$resultat = $this->resultat = $this->Bdd->recupererTous($requete);
53
		$resultat = $this->resultat = $this->Bdd->recupererTous($requete);
53
		$versionResultat = $this->obtenirResultat($resultat);
54
		$versionResultat = $this->obtenirResultat($resultat);
54
		return $versionResultat;
55
		return $versionResultat;
55
	}
56
	}
56
	
57
	
57
 
58
 
58
	//+--------------------------initialisation de paramètres  -------------------------------------------+
59
	//+--------------------------initialisation de paramètres  -------------------------------------------+
59
	
60
	
60
	private function initialiserConfiguration() {
61
	private function initialiserConfiguration() {
61
		$conteneur = new Conteneur();
62
		$conteneur = new Conteneur();
62
		$this->Bdd = $conteneur->getBdd();
63
		$this->Bdd = $conteneur->getBdd();
63
		$this->config = $conteneur->getParametre('Graphiques');
64
		$this->config = $conteneur->getParametre('Graphiques');
64
		$this->convertisseur = $this->config['convertisseur'];
65
		$this->convertisseur = $this->config['convertisseur'];
65
		$this->graduations_id = $this->getParametreTableau('graduations_id');
66
		$this->graduations_id = $this->getParametreTableau('graduations_id');
66
		$this->champs_ontologiques = $this->getParametreTableau('champs_ontologiques');
67
		$this->champs_ontologiques = $this->getParametreTableau('champs_ontologiques');
67
		$this->cheminGraphBase = $this->config['chemin'];
68
		$this->cheminGraphBase = $this->config['chemin'];
68
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
69
		$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
69
								'stockage_chemin' => $this->config['cache']['stockageChemin'],
70
								'stockage_chemin' => $this->config['cache']['stockageChemin'],
70
								'duree_de_vie' => $this->config['cache']['dureeDeVie']);
71
								'duree_de_vie' => $this->config['cache']['dureeDeVie']);
71
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
72
		$this->cache = $conteneur->getCacheSimple($cacheOptions);
72
		$this->definirVersion();
73
		$this->definirVersion();
73
		$this->definirFormat();
74
		$this->definirFormat();
74
		$this->definirTable($this->version);
75
		$this->definirTable($this->version);
75
	}
76
	}
-
 
77
	
-
 
78
	
76
	
79
	
77
	abstract function definirTable($version);
80
	abstract function definirTable($version);
78
	
81
	
79
	
82
	
80
	private function getParametreTableau($cle) {
83
	private function getParametreTableau($cle) {
81
		$tableau = array();
84
		$tableau = array();
82
		$parametre = Config::get($cle);
85
		$parametre = Config::get($cle);
83
		if (empty($parametre) === false) {
86
		if (empty($parametre) === false) {
84
			$tableauPartiel = explode(',', $parametre);
87
			$tableauPartiel = explode(',', $parametre);
85
			$tableauPartiel = array_map('trim', $tableauPartiel);
88
			$tableauPartiel = array_map('trim', $tableauPartiel);
86
			foreach ($tableauPartiel as $champ) {
89
			foreach ($tableauPartiel as $champ) {
87
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
90
				if (strpos($champ, '=') !== false && strlen($champ) >= 3) {
88
					list($cle, $val) = explode('=', $champ);
91
					list($cle, $val) = explode('=', $champ);
89
					$tableau[trim($cle)] = trim($val);
92
					$tableau[trim($cle)] = trim($val);
90
				} else {
93
				} else {
91
					$tableau[] = trim($champ);
94
					$tableau[] = trim($champ);
92
				}
95
				}
93
			}
96
			}
94
		}
97
		}
95
		return $tableau;
98
		return $tableau;
96
	}
99
	}
97
	
100
 
98
	//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
101
	//+--------------------------traitement ressources ou paramètres  -------------------------------------------+
99
	
102
	
100
	//+---- paramètres ----+
103
	//+---- paramètres ----+
-
 
104
	
-
 
105
	private function verifierParametres() {
-
 
106
		if (isset($this->parametres)) {
-
 
107
			$parametres_dispo = array('retour', 'retour.format', 'version.projet');
-
 
108
			$parametres = array_keys($this->parametres);
-
 
109
			foreach ($parametres as $param) {
-
 
110
				if (!in_array($param, $parametres_dispo)) {
-
 
111
					$erreur = "Erreur : Le paramètre $param est inconnu.";
-
 
112
					$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
-
 
113
					throw new Exception($erreur, $code);
-
 
114
				}
-
 
115
			}
-
 
116
		}
-
 
117
		
-
 
118
	}
101
	
119
	
102
	//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
120
	//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
103
	private function definirVersion() { 
121
	private function definirVersion() { 
104
		$this->chargerVersions();
122
		$this->chargerVersions();
105
		if( (!isset($this->parametres['version.projet']) ) || ((isset($this->parametres['version.projet']) )&&
123
		if (!isset($this->parametres['version.projet']) ) {
106
		(($this->parametres['version.projet'] == '+') || ($this->parametres['version.projet'] == '')))){
-
 
107
			$this->version = $this->metadonnees[0]['version'];
124
			$this->version = $this->metadonnees[0]['version'];
-
 
125
		} elseif ($this->parametres['version.projet'] == '+') {
-
 
126
				 $this->version = $this->metadonnees[0]['version'];
108
		} else {
127
		} else {
-
 
128
			if($this->verifierVersion($this->parametres['version.projet'])) {
109
			$this->version = $this->parametres['version.projet'];
129
				$this->version = $this->parametres['version.projet'];
-
 
130
			}else {
-
 
131
				$erreur = "Erreur : La version est inconnue.";
-
 
132
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
-
 
133
				throw new Exception($erreur, $code);
-
 
134
			}
110
		}
135
		}
111
	}
136
	}
-
 
137
	
-
 
138
	private function verifierVersion($version){
-
 
139
		$retour = false;
-
 
140
		foreach ($this->metadonnees as $vers) {
-
 
141
			if ($vers['version'] == $version ) {
-
 
142
				$retour = true;
-
 
143
			}
-
 
144
		}
-
 
145
		return $retour;
112
	
146
	}
113
	private function definirFormat() {
147
	private function definirFormat() {
114
		if (isset($this->parametres['retour.format']) ){
148
		if (isset($this->parametres['retour.format']) ){
115
			if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
149
			if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
116
				$this->largeurSVG = $this->parametres['retour.format'];
150
				$this->largeurSVG = $this->parametres['retour.format'];
117
			}else {
151
			}else {
118
				$erreur = "Erreur : Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
152
				$erreur = "Erreur : valeur inconnue. Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
119
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
153
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
120
				throw new Exception($erreur, $code);
154
				throw new Exception($erreur, $code);
121
			}
155
			}
122
		}
156
		}
123
		if (!isset($this->parametres['retour']) ){
157
		if (!isset($this->parametres['retour']) ){
124
			$this->parametres['retour'] = 'image/svg+xml';
158
			$this->parametres['retour'] = 'image/svg+xml';
125
		
159
		
126
		}else {
160
		}else {
127
			if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
161
			if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
128
				$erreur = "Erreur : choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
162
				$erreur = "Erreur : valeur inconnue. Choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
129
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
163
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
130
				throw new Exception($erreur, $code);
164
				throw new Exception($erreur, $code);
131
			}
165
			}
132
		}
166
		}
133
	}
167
	}
134
	
168
	
135
	
169
	
136
	
170
	
137
	private function chargerVersions() {
171
	private function chargerVersions() {
138
		$requete = "SELECT version ".
172
		$requete = "SELECT version ".
139
							"FROM ".Config::get('bdd_table_meta')." ".
173
							"FROM ".Config::get('bdd_table_meta')." ".
140
							"ORDER BY date_creation DESC ";
174
							"ORDER BY date_creation DESC ";
141
		$resultats = $this->Bdd->recupererTous($requete);
175
		$resultats = $this->Bdd->recupererTous($requete);
142
		if (!is_array($resultats) || count($resultats) <= 0) {
176
		if (!is_array($resultats) || count($resultats) <= 0) {
143
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
177
			$message = "Les méta-données n'ont pu être chargée pour la ressource demandée";
144
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
178
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
145
			throw new Exception($message, $code);
179
			throw new Exception($message, $code);
146
		}
180
		}
147
	
181
	
148
		$this->metadonnees = $resultats;
182
		$this->metadonnees = $resultats;
149
	}
183
	}
150
	
184
	
151
	//+----- ressources -----+
185
	//+----- ressources -----+
152
	
186
	
153
	
187
	
154
	public function traiterRessources() {
188
	public function traiterRessources() {
155
		if(isset($this->ressources)) {
189
		if(isset($this->ressources)) {
156
			$this->traiterTypeGraphique();
190
			$this->traiterTypeGraphique();
157
			$this->traiterReferentielEtNum();
191
			$this->traiterReferentielEtNum();
158
		} else {
192
		} else {
159
			$e = 'Erreur dans l\'url de votre requête : </br> ressources insuffisantes.';
193
			$e = 'Erreur dans l\'url de votre requête : </br> ressources insuffisantes.';
160
			throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
194
			throw new Exception( $e, RestServeur::HTTP_CODE_MAUVAISE_REQUETE);
161
		}
195
		}
162
	}
196
	}
163
	
197
	
164
	abstract function traiterReferentielEtNum();
198
	abstract function traiterReferentielEtNum();
165
	abstract function traiterTypeGraphique();
199
	abstract function traiterTypeGraphique();
166
	
200
	
167
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
201
	//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
168
	
202
	
169
	public function assemblerLaRequete() {
203
	public function assemblerLaRequete() {
170
		$requete = 	' SELECT '.$this->requete_champs.'  FROM '.$this->table.' '.$this->retournerRequeteCondition();
204
		$requete = 	' SELECT '.$this->requete_champs.'  FROM '.$this->table.' '.$this->retournerRequeteCondition();
171
		return $requete;
205
		return $requete;
172
	}
206
	}
173
	
207
	
174
	public  function retournerRequeteCondition() {
208
	public  function retournerRequeteCondition() {
175
		$condition = '';
209
		$condition = '';
176
		if ($this->requete_condition !== "") {
210
		if ($this->requete_condition !== "") {
177
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
211
			$condition = ' WHERE '.implode(' AND ', $this->requete_condition);
178
		}
212
		}
179
		return $condition;
213
		return $condition;
180
	}
214
	}
181
	
215
	
182
	//+-------------------------- formatage du résultat  -------------------------------------------+
216
	//+-------------------------- formatage du résultat  -------------------------------------------+
183
 
217
 
184
	public function obtenirResultat($resultat) {
218
	public function obtenirResultat($resultat) {
185
		if ($resultat == ""){
219
		if ($resultat == ""){
186
			$message = 'La requête SQL formée comporte une erreur!';
220
			$message = 'La requête SQL formée comporte une erreur!';
187
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
221
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
188
			throw new Exception($message, $code);
222
			throw new Exception($message, $code);
189
		}elseif ($resultat) {
223
		}elseif ($resultat) {
190
			if ((count($this->ressources)) != 0) {
224
			if ((count($this->ressources)) != 0) {
191
				//$Atraiter = array_filter($resultat[0],function($var){return ($var != '');});
225
				//$Atraiter = array_filter($resultat[0],function($var){return ($var != '');});
192
				foreach ($resultat[0] as $champs => $valeur) {
226
				foreach ($resultat[0] as $champs => $valeur) {
193
					if ($valeur !== '') {
227
					if ($valeur !== '') {
194
						$Atraiter[$champs] = $valeur;
228
						$Atraiter[$champs] = $valeur;
195
					}
229
					}
196
				}
230
				}
197
				if (!empty($Atraiter)) {
231
				if (!empty($Atraiter)) {
198
					$this->traiterValeursEcologiques($Atraiter);
232
					$this->traiterValeursEcologiques($Atraiter);
199
					$svg = $this->genererSVG();
233
					$svg = $this->genererSVG();
200
					$resultat = new ResultatService();
234
					$resultat = new ResultatService();
201
					$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
235
					$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
202
					$resultat->mime = $this->parametres['retour'];
236
					$resultat->mime = $this->parametres['retour'];
203
				} else {
237
				} else {
204
					$resultat = null; 
238
					$resultat = null; 
205
				}
239
				}
206
			}
240
			}
207
		} else {
241
		} else {
208
			$resultat = null;
242
			$resultat = null;
209
		}
243
		}
210
		return $resultat;
244
		return $resultat;
211
	}
245
	}
212
	
246
	
213
	
247
	
214
	
248
	
215
	
249
	
216
	//+----- modification svg -----+
250
	//+----- modification svg -----+
217
	
251
	
218
	
252
	
219
 
253
 
220
	public function traiterValeursEcologiques($valeur){
254
	public function traiterValeursEcologiques($valeur){
221
		$this->valeurs_champs = $valeur; 
255
		$this->valeurs_champs = $valeur; 
222
	
256
	
223
		foreach($this->valeurs_champs as $cle => $val){
257
		foreach($this->valeurs_champs as $cle => $val){
224
				if (preg_match("/ve_humidite_edaph/", $cle)) {
258
				if (preg_match("/ve_humidite_edaph/", $cle)) {
225
					$this->valeurs_en_pourcentage[$cle] = round($val/13,1);
259
					$this->valeurs_en_pourcentage[$cle] = round($val/13,1);
226
				} elseif (preg_match("/ve_salinite/", $cle)) {
260
				} elseif (preg_match("/ve_salinite/", $cle)) {
227
					$this->valeurs_en_pourcentage[$cle] = round(($val+1)/11,1);
261
					$this->valeurs_en_pourcentage[$cle] = round(($val+1)/11,1);
228
				} else {
262
				} else {
229
					$this->valeurs_en_pourcentage[$cle] = round($val/10,1);
263
					$this->valeurs_en_pourcentage[$cle] = round($val/10,1);
230
				}
264
				}
231
		}
265
		}
232
	}
266
	}
233
	
267
	
234
	
268
	
235
	
269
	
236
	public function genererSVG(){
270
	public function genererSVG(){
237
		$svg = null;
271
		$svg = null;
238
		$this->dom = new DOMDocument('1.0', 'UTF-8');
272
		$this->dom = new DOMDocument('1.0', 'UTF-8');
239
		$this->dom->validateOnParse = true;
273
		$this->dom->validateOnParse = true;
240
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
274
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
241
		$this->dom->load($fichierSvg);
275
		$this->dom->load($fichierSvg);
242
		$this->changerValeursSVG();
276
		$this->changerValeursSVG();
243
			$svg = $this->dom->saveXML();
277
			$svg = $this->dom->saveXML();
244
		return $svg;
278
		return $svg;
245
	}
279
	}
246
	
280
	
247
	abstract function changerValeursSVG();
281
	abstract function changerValeursSVG();
248
	
282
	
249
	public function recupererOntologies($valeur, $champs){
283
	public function recupererOntologies($valeur, $champs){
250
		$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
284
		$url = $this->ajouterHref('ontologies',$this->champs_ontologiques[$champs].':'.urlencode(urlencode($valeur)));
251
		$val = $this->consulterHref($url);
285
		$val = $this->consulterHref($url);
252
		return $val;
286
		return $val;
253
	}
287
	}
254
	
288
	
255
	public function traiterIntermediaires($valeurTexte,$champsOntologie, $champsTable){
289
	public function traiterIntermediaires($valeurTexte,$champsOntologie, $champsTable){
256
		if (preg_match("/(?:I|i)nterm(?:é|e)diaire(?:s)*/", $valeurTexte )) {
290
		if (preg_match("/(?:I|i)nterm(?:é|e)diaire(?:s)*/", $valeurTexte )) {
257
			$prec = $this->recupererOntologies(($this->valeurs_champs[$champsTable]-1), $champsOntologie );
291
			$prec = $this->recupererOntologies(($this->valeurs_champs[$champsTable]-1), $champsOntologie );
258
			$suiv = $this->recupererOntologies(($this->valeurs_champs[$champsTable]+1), $champsOntologie );
292
			$suiv = $this->recupererOntologies(($this->valeurs_champs[$champsTable]+1), $champsOntologie );
259
			$valeurTexte = "Intermédiaires entre $prec->nom et $suiv->nom ";
293
			$valeurTexte = "Intermédiaires entre $prec->nom et $suiv->nom ";
260
		}
294
		}
261
		return $valeurTexte;
295
		return $valeurTexte;
262
	}
296
	}
263
	
297
	
264
	/// +---- convertir png ----+
298
	/// +---- convertir png ----+
265
	
299
	
266
	public function convertirEnPNG($svg) {
300
	public function convertirEnPNG($svg) {
267
		$png = null;
301
		$png = null;
268
	
302
	
269
		if (isset($this->convertisseur)) {
303
		if (isset($this->convertisseur)) {
270
			if ($this->convertisseur == 'imagick') {
304
			if ($this->convertisseur == 'imagick') {
271
				if (extension_loaded('imagick')) {
305
				if (extension_loaded('imagick')) {
272
					$png = $this->convertirEnPNGAvecImageMagick($svg);
306
					$png = $this->convertirEnPNGAvecImageMagick($svg);
273
				} else {
307
				} else {
274
					$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
308
					$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
275
					$code = RestServeur::HTTP_CODE_ERREUR;
309
					$code = RestServeur::HTTP_CODE_ERREUR;
276
					throw new Exception($message, $code);
310
					throw new Exception($message, $code);
277
				}
311
				}
278
			} else if ($this->convertisseur == 'rsvg') {
312
			} else if ($this->convertisseur == 'rsvg') {
279
				$png = $this->convertirEnPNGAvecRsvg($svg);
313
				$png = $this->convertirEnPNGAvecRsvg($svg);
280
			} else {
314
			} else {
281
				$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
315
				$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
282
								"des convertisseurs disponibles : imagick, rsvg.";
316
								"des convertisseurs disponibles : imagick, rsvg.";
283
				$code = RestServeur::HTTP_CODE_ERREUR;
317
				$code = RestServeur::HTTP_CODE_ERREUR;
284
				throw new Exception($message, $code);
318
				throw new Exception($message, $code);
285
			}
319
			}
286
		} else {
320
		} else {
287
			$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
321
			$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
288
			$code = RestServeur::HTTP_CODE_ERREUR;
322
			$code = RestServeur::HTTP_CODE_ERREUR;
289
			throw new Exception($message, $code);
323
			throw new Exception($message, $code);
290
		}
324
		}
291
		return $png;
325
		return $png;
292
	}
326
	}
293
	
327
	
294
	public function convertirEnPNGAvecImageMagick($svg) {
328
	public function convertirEnPNGAvecImageMagick($svg) {
295
		$convertisseur = new Imagick();
329
		$convertisseur = new Imagick();
296
		$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
330
		$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
297
		$convertisseur->readImageBlob($svg);
331
		$convertisseur->readImageBlob($svg);
298
		$convertisseur->setImageFormat('png32');
332
		$convertisseur->setImageFormat('png32');
299
		$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
333
		$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
300
		$png = $convertisseur->getImageBlob();
334
		$png = $convertisseur->getImageBlob();
301
		$convertisseur->clear();
335
		$convertisseur->clear();
302
		$convertisseur->destroy();
336
		$convertisseur->destroy();
303
		return $png;
337
		return $png;
304
	}
338
	}
305
	
339
	
306
	public function convertirEnPNGAvecRsvg($svg) {
340
	public function convertirEnPNGAvecRsvg($svg) {
307
		$idFichier = $this->getIdFichier();
341
		$idFichier = $this->getIdFichier();
308
		$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
342
		$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
309
		$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
343
		$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
310
		file_put_contents($fichierSvg, $svg);
344
		file_put_contents($fichierSvg, $svg);
311
		$commande = "rsvg-convert  $fichierSvg -b #F8F8F8 -w $this->largeurSVG -a -o $fichierPng";
345
		$commande = "rsvg-convert  $fichierSvg -b #F8F8F8 -w $this->largeurSVG -a -o $fichierPng";
312
		$rsvg = exec($commande);
346
		$rsvg = exec($commande);
313
		$this->indexerFichierPng($fichierPng);
347
		$this->indexerFichierPng($fichierPng);
314
		$png = file_get_contents($fichierPng);
348
		$png = file_get_contents($fichierPng);
315
		return $png;
349
		return $png;
316
	}
350
	}
317
	
351
	
318
	public function indexerFichierPng($fichierPng) {
352
	public function indexerFichierPng($fichierPng) {
319
		$img = imagecreatefrompng($fichierPng);
353
		$img = imagecreatefrompng($fichierPng);
320
		imagetruecolortopalette($img, false, 32);
354
		imagetruecolortopalette($img, false, 32);
321
		imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
355
		imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
322
	}
356
	}
323
	
357
	
324
	public function getIdFichier(){
358
	public function getIdFichier(){
325
		$idfichier = str_replace(".","-",$this->ressources[1]);
359
		$idfichier = str_replace(".","-",$this->ressources[1]);
326
		$idfichier = str_replace(':','-',$idfichier);
360
		$idfichier = str_replace(':','-',$idfichier);
327
		$idfichier .= "-".$this->ressources[0];
361
		$idfichier .= "-".$this->ressources[0];
328
		return $idfichier;
362
		return $idfichier;
329
	}
363
	}
330
}
364
}
331
?>
365
?>