Subversion Repositories eFlore/Projets.eflore-projets

Compare Revisions

Ignore whitespace Rev 409 → Rev 410

/trunk/services/modules/0.1/baseflor/Graphiques.php
32,7 → 32,7
private $serviceNom = 'Graphiques';
private $valeurs_en_pourcentage ;
private $dom;
private $largeurSVG;
private $largeurSVG="500";
private $graduations_id = array ("zero" => 0 ,"un"=> 0.1, "deux" => 0.2 , "trois" => 0.3, "quatre" => 0.4,
"cinq" => 0.5, "six" => 0.6 ,"sept" => 0.7, "huit" => 0.8, "neuf" => 0.9,
"dix" => 1 );
42,7 → 42,6
$this->parametres = $parametres;
$this->initialiserConfiguration();
$resultats = '';
 
$this->table = Config::get('bdd_table')."_v".$this->version;
$this->traiterRessources();
$requete = $this->assemblerLaRequete();
59,9 → 58,13
$this->config = $conteneur->getParametre('Graphiques');
$this->convertisseur = $this->config['convertisseur'];
$this->cheminGraphBase = $this->config['chemin'];
$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
'stockage_chemin' => $this->config['cache']['stockageChemin'],
'duree_de_vie' => $this->config['cache']['dureeDeVie']);
$this->cache = $conteneur->getCacheSimple($cacheOptions);
$this->chargerVersions();
$this->definirVersion();
$this->definirTailleSVG();
$this->definirFormat();
}
//on n'affiche qu'une version de graphique à la fois ( la dernière ou celle demandée )
74,14 → 77,29
}
}
private function definirTailleSVG() {
if (!isset($this->parametres['retour.format']) ){
$this->largeurSVG="500";
} else {
$this->largeurSVG= $this->parametres['retour.format'];
private function definirFormat() {
if (isset($this->parametres['retour.format']) ){
if (preg_match("/^[0-9]+$/", $this->parametres['retour.format'])){
$this->largeurSVG= $this->parametres['retour.format'];
}else {
$erreur = "Erreur : Entrez la largeur voulue (en pixels) pour le paramètre retour.format.";
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($erreur, $code);
}
}
if (!isset($this->parametres['retour']) ){
$this->parametres['retour'] = 'image/svg+xml';
}else {
if (( $this->parametres['retour'] != 'image/svg+xml')&& ( $this->parametres['retour'] != 'image/png')){
$erreur = "Erreur : choisissez le format de retour pour le paramètre retour : image/svg%2Bxml ou image/png.";
$code = RestServeur::HTTP_CODE_MAUVAISE_REQUETE;
throw new Exception($erreur, $code);
}
}
}
 
private function chargerVersions() {
$requete = "SELECT version ".
"FROM ".Config::get('bdd_table_meta')." ".
176,9 → 194,10
$i = 0;
$svg = $this->genererSVG();
$resultat = new ResultatService();
$resultat->corps = $svg;
$resultat->mime = 'image/svg+xml';
}
$resultat->corps = ($this->parametres['retour'] == 'image/png') ? $this->convertirEnPNG($svg) : $svg;
$resultat->mime = $this->parametres['retour'];
}
} else {
$message = 'Les données recherchées sont introuvables.';
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
230,6 → 249,69
}
}
private function convertirEnPNG($svg) {
$png = null;
if (isset($this->convertisseur)) {
if ($this->convertisseur == 'imagick') {
if (extension_loaded('imagick')) {
$png = $this->convertirEnPNGAvecImageMagick($svg);
} else {
$message = "Impossible de générer l'image sur le serveur. Extension ImageMagick absente.";
$code = RestServeur::HTTP_CODE_ERREUR;
throw new Exception($message, $code);
}
} else if ($this->convertisseur == 'rsvg') {
$png = $this->convertirEnPNGAvecRsvg($svg);
} else {
$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas partie de la liste ".
"des convertisseurs disponibles : imagick, rsvg.";
$code = RestServeur::HTTP_CODE_ERREUR;
throw new Exception($message, $code);
}
} else {
$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
$code = RestServeur::HTTP_CODE_ERREUR;
throw new Exception($message, $code);
}
return $png;
}
private function convertirEnPNGAvecImageMagick($svg) {
$convertisseur = new Imagick();
$convertisseur->setBackgroundColor(new ImagickPixel('transparent'));
$convertisseur->readImageBlob($svg);
$convertisseur->setImageFormat('png32');
$convertisseur->resizeImage($this->largeurSVG, 0 , imagick::FILTER_LANCZOS, 0, true);
$png = $convertisseur->getImageBlob();
$convertisseur->clear();
$convertisseur->destroy();
return $png;
}
private function convertirEnPNGAvecRsvg($svg) {
$idFichier = $this->getIdFichier();
$fichierPng = $this->config['cache']['stockageChemin']."".$idFichier.'.png';
$fichierSvg = $this->config['cache']['stockageChemin']."".$idFichier.'.svg';
file_put_contents($fichierSvg, $svg);
$commande = "rsvg-convert $fichierSvg -d 75 -p 75 -o $fichierPng";
$rsvg = exec($commande);
$this->indexerFichierPng($fichierPng);
$png = file_get_contents($fichierPng);
return $png;
}
private function indexerFichierPng($fichierPng) {
$img = imagecreatefrompng($fichierPng);
imagetruecolortopalette($img, false, 32);
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
}
private function getIdFichier(){
$idfichier = str_replace(".","-",$this->ressources[1]);
$idfichier = str_replace(':','-',$idfichier);
return $idfichier;
}
//+--------------------------FONCTIONS D'ASSEMBLAGE DE LA REQUETE-------------------------------------------+
public function assemblerLaRequete() {