| Line 19... |
Line 19... |
| 19 |
private $ressources = array();
|
19 |
private $ressources = array();
|
| Line 20... |
Line 20... |
| 20 |
|
20 |
|
| 21 |
const CODE_REFTAX_DEFAUT = 'bdtfx';
|
21 |
const CODE_REFTAX_DEFAUT = 'bdtfx';
|
| 22 |
const TYPE_ID_DEFAUT = 'nn';
|
22 |
const TYPE_ID_DEFAUT = 'nn';
|
| 23 |
const CARTE_DEFAUT = 'france_02';
|
23 |
const CARTE_DEFAUT = 'france_02';
|
| 24 |
const FORMAT_DEFAUT = '550';
|
24 |
const FORMAT_DEFAUT = '587x550';
|
| 25 |
const VERSION_DEFAUT = '+';
|
25 |
const VERSION_DEFAUT = '+';
|
| 26 |
const MIME_SVG = 'image/svg+xml';
|
26 |
const MIME_SVG = 'image/svg+xml';
|
| 27 |
const MIME_PNG = 'image/png';
|
27 |
const MIME_PNG = 'image/png';
|
| Line 28... |
Line 28... |
| 28 |
const PRESENCE_CHOROLOGIE = '1';
|
28 |
const PRESENCE_CHOROLOGIE = '1';
|
| - |
|
29 |
|
| 29 |
|
30 |
private $config = array();
|
| 30 |
private $config = array();
|
31 |
private $convertisseur = '';
|
| 31 |
private $cheminCartesBase = '';
|
32 |
private $cheminCartesBase = '';
|
| 32 |
private $formatsSupportes = array(self::MIME_SVG, self::MIME_PNG);
|
33 |
private $formatsSupportes = array(self::MIME_SVG, self::MIME_PNG);
|
| 33 |
private $reftaxSupportes = array(self::CODE_REFTAX_DEFAUT);
|
34 |
private $reftaxSupportes = array(self::CODE_REFTAX_DEFAUT);
|
| Line 48... |
Line 49... |
| 48 |
|
49 |
|
| 49 |
public function __construct(Conteneur $conteneur) {
|
50 |
public function __construct(Conteneur $conteneur) {
|
| 50 |
$this->Bdd = $conteneur->getBdd();
|
51 |
$this->Bdd = $conteneur->getBdd();
|
| 51 |
$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
|
52 |
$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
|
| - |
|
53 |
$this->config = $conteneur->getParametre('Cartes');
|
| 52 |
$this->config = $conteneur->getParametre('Cartes');
|
54 |
$this->convertisseur = $this->config['convertisseur'];
|
| 53 |
$this->tableMeta = $conteneur->getParametre('bdd_table_meta');
|
55 |
$this->tableMeta = $conteneur->getParametre('bdd_table_meta');
|
| 54 |
$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
|
56 |
$this->tableOntologie = $conteneur->getParametre('bdd_table_ontologies');
|
| 55 |
$this->cheminCartesBase = $this->config['chemin'];
|
57 |
$this->cheminCartesBase = $this->config['chemin'];
|
| 56 |
$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
|
58 |
$cacheOptions = array('mise_en_cache' => $this->config['cache']['miseEnCache'],
|
| Line 399... |
Line 401... |
| 399 |
return $titre;
|
401 |
return $titre;
|
| 400 |
}
|
402 |
}
|
| Line 401... |
Line 403... |
| 401 |
|
403 |
|
| 402 |
private function convertirEnPNG($svg) {
|
404 |
private function convertirEnPNG($svg) {
|
| - |
|
405 |
$png = null;
|
| - |
|
406 |
if (isset($this->convertisseur)) {
|
| 403 |
$png = null;
|
407 |
if ($this->convertisseur == 'imagick') {
|
| 404 |
if (extension_loaded('imagick')) {
|
408 |
if (extension_loaded('imagick')) {
|
| - |
|
409 |
$png = $this->convertirEnPNGAvecImageMagick($svg);
|
| - |
|
410 |
} else {
|
| - |
|
411 |
$message = "Impossible de générer l'image sur le serveur. Extenssion ImageMagick abscente.";
|
| - |
|
412 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
| - |
|
413 |
throw new Exception($message, $code);
|
| - |
|
414 |
}
|
| - |
|
415 |
} else if ($this->convertisseur == 'rsvg') {
|
| - |
|
416 |
$png = $this->convertirEnPNGAvecRsvg($svg);
|
| - |
|
417 |
} else {
|
| - |
|
418 |
$message = "Le convertisseur indiqué '{$this->convertisseur}' ne fait pas parti de la liste ".
|
| - |
|
419 |
"des convertisseurs disponibles : imagick, rsvg.";
|
| - |
|
420 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
| - |
|
421 |
throw new Exception($message, $code);
|
| 405 |
$png = $this->convertirEnPNGAvecImageMagick($svg);
|
422 |
}
|
| 406 |
} else {
|
423 |
} else {
|
| 407 |
$message = "Impossible de générer l'image sur le serveur. Extenssion ImageMagick abscente.";
|
424 |
$message = "Veuillez indiquer le convertisseur de svg à utiliser pour le service.";
|
| 408 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
425 |
$code = RestServeur::HTTP_CODE_ERREUR;
|
| 409 |
throw new Exception($message, $code);
|
426 |
throw new Exception($message, $code);
|
| 410 |
}
|
427 |
}
|
| 411 |
return $svg;
|
428 |
return $png;
|
| Line 412... |
Line 429... |
| 412 |
}
|
429 |
}
|
| 413 |
|
430 |
|
| - |
|
431 |
private function convertirEnPNGAvecImageMagick($svg) {
|
| 414 |
private function convertirEnPNGAvecImageMagick($svg) {
|
432 |
$convertisseur = new Imagick();
|
| 415 |
$convertisseur = new Imagick();
|
433 |
$convertisseur->setBackgroundColor(new ImagickPixel('transparent'));
|
| 416 |
$convertisseur->readImageBlob($svg);
|
434 |
$convertisseur->readImageBlob($svg);
|
| 417 |
$convertisseur->setImageFormat("png24");
|
435 |
$convertisseur->setImageFormat('png32');
|
| 418 |
$convertisseur->resizeImage($this->imgLargeur, $this->imgHauteur, imagick::FILTER_LANCZOS, 0);
|
436 |
$convertisseur->resizeImage($this->imgLargeur, $this->imgHauteur, imagick::FILTER_LANCZOS, 0, true);
|
| 419 |
$png = $convertisseur->getImageBlob();
|
437 |
$png = $convertisseur->getImageBlob();
|
| 420 |
$convertisseur->clear();
|
438 |
$convertisseur->clear();
|
| 421 |
$convertisseur->destroy();
|
439 |
$convertisseur->destroy();
|
| Line -... |
Line 440... |
| - |
|
440 |
return $png;
|
| - |
|
441 |
}
|
| - |
|
442 |
|
| - |
|
443 |
private function convertirEnPNGAvecRsvg($svg) {
|
| - |
|
444 |
$idFichier = md5($svg);
|
| - |
|
445 |
$fichierPng = $this->config['cache']['stockageChemin'].$idFichier.'.png';
|
| - |
|
446 |
$fichierSvg = $this->config['cache']['stockageChemin'].$idFichier.'.svg';
|
| - |
|
447 |
file_put_contents($fichierSvg, $svg);
|
| - |
|
448 |
$rsvg = exec("rsvg-convert $fichierSvg -d 75 -p 75 -o $fichierPng");
|
| - |
|
449 |
$this->indexerFichierPng($fichierPng);
|
| - |
|
450 |
$png = file_get_contents($fichierPng);
|
| - |
|
451 |
return $png;
|
| - |
|
452 |
}
|
| - |
|
453 |
|
| - |
|
454 |
private function indexerFichierPng($fichierPng) {
|
| - |
|
455 |
$img = imagecreatefrompng($fichierPng);
|
| - |
|
456 |
imagetruecolortopalette($img, false, 32);
|
| - |
|
457 |
imagealphablending($img, false);
|
| - |
|
458 |
$alpha = imagecolorallocatealpha($img, 0, 0, 0, 127);
|
| - |
|
459 |
imagefill($img, 0, 0, $alpha);
|
| - |
|
460 |
imagesavealpha($img, true);
|
| 422 |
return $png;
|
461 |
imagepng($img, $fichierPng, 9, PNG_ALL_FILTERS);
|
| 423 |
}
|
462 |
}
|
| 424 |
|
463 |
|
| 425 |
public function getParametreTableau($cle) {
|
464 |
public function getParametreTableau($cle) {
|
| 426 |
$tableau = array();
|
465 |
$tableau = array();
|