Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev 801 Rev 807
Line 450... Line 450...
450
		if (! isset($this->RestClient)) {
450
		if (! isset($this->RestClient)) {
451
			$this->RestClient = new RestClient();
451
			$this->RestClient = new RestClient();
452
		}
452
		}
453
		return $this->RestClient;
453
		return $this->RestClient;
454
	}
454
	}
-
 
455
 
-
 
456
 
-
 
457
	/**
-
 
458
	 * Génération de fichiers pour les cartes
-
 
459
	 */
-
 
460
	static function convertirEnPNGAvecRsvg($idFichier, $chemin, $svg) {
-
 
461
		// test répertoire de cache
-
 
462
		if(!is_dir($chemin)) {
-
 
463
			mkdir($chemin, 0777, true);
-
 
464
		}
-
 
465
		if(!is_dir($chemin)) {
-
 
466
			error_log(__FILE__ . ": can't create cache {$chemin}");
-
 
467
			return NULL;
-
 
468
		}
-
 
469
 
-
 
470
		// test présence du binaire de conversion (rsvg)
-
 
471
		/*
-
 
472
		  // `which` no possible using safe-mode...
-
 
473
		$i = $s = NULL;
-
 
474
		exec('which rsvg-convert', $s, $i);
-
 
475
		if($i != 0) {
-
 
476
			error_log(__FILE__ . ": no rsvg-convert binary");
-
 
477
			return NULL;
-
 
478
		}
-
 
479
		*/
-
 
480
		// conversion svg => png
-
 
481
		$fichierPng = $chemin.$idFichier.'.png';
-
 
482
		$fichierSvg = $chemin.$idFichier.'.svg';
-
 
483
		file_put_contents($fichierSvg, $svg);
-
 
484
		$i = $s = NULL;
-
 
485
		$rsvg = exec("rsvg-convert $fichierSvg -d 75 -p 75 -o $fichierPng", $s, $i);
-
 
486
		if($i != 0) {
-
 
487
			error_log(__FILE__ . ": `rsvg-convert $fichierSvg -o $fichierPng` returned $i: " . implode(', ', $s));
-
 
488
			return NULL;
-
 
489
		}
-
 
490
 
-
 
491
		self::indexerFichierPng($fichierPng);
-
 
492
		return file_get_contents($fichierPng);
-
 
493
	}
-
 
494
 
-
 
495
	static function indexerFichierPng($fichierPng) {
-
 
496
		$img = imagecreatefrompng($fichierPng);
-
 
497
		imagetruecolortopalette($img, false, 32);
-
 
498
		$blanc = imagecolorallocate($img, 255, 255, 255);
-
 
499
		imagefill($img, 0, 0, $blanc);
-
 
500
		imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
-
 
501
	}
455
}
502
}
456
?>
503
?>
457
504