Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 506 | Rev 560 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 506 Rev 512
Line 37... Line 37...
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 $hauteurSVG;
42
	protected $valeurs_champs;
43
	protected $valeurs_champs;
Line -... Line 44...
-
 
44
	
43
	
45
	
44
	
46
	
45
	public function consulter($ressources, $parametres) {
47
	public function consulter($ressources, $parametres) {
46
		$this->ressources = $ressources;
48
		$this->ressources = $ressources;
47
		$this->parametres = $parametres;
49
		$this->parametres = $parametres;
Line 145... Line 147...
145
		return $retour;
147
		return $retour;
146
	}
148
	}
147
	private function definirFormat() {
149
	private function definirFormat() {
148
		if (isset($this->parametres['retour.format']) ){
150
		if (isset($this->parametres['retour.format']) ){
149
			if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
151
			if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
-
 
152
				if ($this->parametres['retour.format'] > 0) {
150
				$this->largeurSVG = $this->parametres['retour.format'];
153
					$this->largeurSVG = $this->parametres['retour.format'];
-
 
154
				} else {
-
 
155
					$erreur = "Erreur : valeur pour retour.format négative ou égale à 0.";
-
 
156
					$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
-
 
157
					throw new Exception($erreur, $code);
-
 
158
				}
151
			}else {
159
			}else {
152
				$erreur = "Erreur : valeur inconnue. Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
160
				$erreur = "Erreur : valeur inconnue. Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
153
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
161
				$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
154
				throw new Exception($erreur, $code);
162
				throw new Exception($erreur, $code);
155
			}
163
			}
Line 263... Line 271...
263
					$this->valeurs_en_pourcentage[$cle] = round($val/10,1);
271
					$this->valeurs_en_pourcentage[$cle] = round($val/10,1);
264
				}
272
				}
265
		}
273
		}
266
	}
274
	}
Line -... Line 275...
-
 
275
	
-
 
276
	public function donnerHauteur($ancienne_largeur, $ancienne_hauteur) {
-
 
277
		$nouvelle_largeur = $this->largeurSVG;
-
 
278
		$ancienne_largeur = str_replace('px','',$ancienne_largeur);
-
 
279
		$ancienne_hauteur = str_replace('px','',$ancienne_hauteur);
-
 
280
		$rapport =   $nouvelle_largeur / $ancienne_largeur ;
-
 
281
		$nouvelle_hauteur = $ancienne_hauteur * $rapport;
-
 
282
		$this->hauteurSVG = $nouvelle_hauteur;
267
	
283
	}
-
 
284
	
-
 
285
	public function ajusterFormatSVG(){
-
 
286
		$svg = $this->dom->getElementsByTagName("svg")->item(0);
-
 
287
		$largeur = $svg->getAttribute('width');
-
 
288
		$hauteur = $svg->getAttribute('height');
-
 
289
		$this->donnerHauteur($largeur , $hauteur);
-
 
290
		$svg->setAttribute('width',$this->largeurSVG.'px');
-
 
291
		$svg->setAttribute('height',$this->hauteurSVG.'px');
-
 
292
		
Line 268... Line 293...
268
	
293
	}
269
	
294
	
270
	public function genererSVG(){
295
	public function genererSVG(){
271
		$svg = null;
296
		$svg = null;
272
		$this->dom = new DOMDocument('1.0', 'UTF-8');
297
		$this->dom = new DOMDocument('1.0', 'UTF-8');
273
		$this->dom->validateOnParse = true;
298
		$this->dom->validateOnParse = true;
274
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
299
		$fichierSvg = $this->cheminGraphBase."".$this->nomGraphique.".svg";
275
		$this->dom->load($fichierSvg);
300
		$this->dom->load($fichierSvg);
276
		$this->changerValeursSVG();
301
		$this->changerValeursSVG();
277
			$svg = $this->dom->saveXML();
302
		$svg = $this->dom->saveXML();
Line 278... Line 303...
278
		return $svg;
303
		return $svg;
Line 328... Line 353...
328
	public function convertirEnPNGAvecImageMagick($svg) {
353
	public function convertirEnPNGAvecImageMagick($svg) {
329
		$convertisseur = new Imagick();
354
		$convertisseur = new Imagick();
330
		$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
355
		$convertisseur->setBackgroundColor(new ImagickPixel('#F8F8F8'));
331
		$convertisseur->readImageBlob($svg);
356
		$convertisseur->readImageBlob($svg);
332
		$convertisseur->setImageFormat('png32');
357
		$convertisseur->setImageFormat('png32');
333
		$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
358
		$convertisseur->resizeImage($this->largeurSVG,$this->hauteurSVG, imagick::FILTER_LANCZOS, 0, true);
334
		$png = $convertisseur->getImageBlob();
359
		$png = $convertisseur->getImageBlob();
335
		$convertisseur->clear();
360
		$convertisseur->clear();
336
		$convertisseur->destroy();
361
		$convertisseur->destroy();
337
		return $png;
362
		return $png;
338
	}
363
	}
Line 340... Line 365...
340
	public function convertirEnPNGAvecRsvg($svg) {
365
	public function convertirEnPNGAvecRsvg($svg) {
341
		$idFichier = $this->getIdFichier();
366
		$idFichier = $this->getIdFichier();
342
		$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
367
		$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
343
		$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
368
		$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
344
		file_put_contents($fichierSvg, $svg);
369
		file_put_contents($fichierSvg, $svg);
345
		$commande = "rsvg-convert  $fichierSvg -b #F8F8F8 -w $this->largeurSVG -a -o $fichierPng";
370
		$commande = "rsvg-convert  $fichierSvg -w ".$this->largeurSVG ." -h ".$this->hauteurSVG ." -o $fichierPng";
-
 
371
		//echo $commande; exit;
346
		$rsvg = exec($commande);
372
		$rsvg = exec($commande);
347
		$this->indexerFichierPng($fichierPng);
373
		$this->indexerFichierPng($fichierPng);
348
		$png = file_get_contents($fichierPng);
374
		$png = file_get_contents($fichierPng);
349
		return $png;
375
		return $png;
350
	}
376
	}