1203 |
jpm |
1 |
<?php
|
|
|
2 |
// declare(encoding='UTF-8');
|
|
|
3 |
/**
|
|
|
4 |
* Script d'extration des métadonnées des images pour intégration dans la BDD v2.
|
|
|
5 |
*
|
|
|
6 |
* @category php 5.2
|
|
|
7 |
* @package Cel/Scripts
|
|
|
8 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
9 |
* @copyright Copyright (c) 2012, Tela Botanica (accueil@tela-botanica.org)
|
|
|
10 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
11 |
* @license http://www.gnu.org/licenses/gpl.html Licence GNU-GPL
|
|
|
12 |
* @version $Id$
|
|
|
13 |
*/
|
|
|
14 |
class ExtracteurMeta extends Cel {
|
|
|
15 |
|
|
|
16 |
public function executer() {
|
|
|
17 |
try {
|
|
|
18 |
echo "EXTRACTION des MÉTADONNÉES\n";
|
|
|
19 |
echo "Vérification config : ".$this->verifierConfig();
|
|
|
20 |
|
|
|
21 |
} catch (Exception $e) {
|
|
|
22 |
$code = $e->getCode();
|
|
|
23 |
$message = $e->getMessage();
|
|
|
24 |
die("\n$code : $message\n");
|
|
|
25 |
}
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
private function verifierConfig() {
|
|
|
29 |
if (empty($this->config['cel']['chemin_images'])) {
|
|
|
30 |
$message = "Vous devez indiquer le dossier contenant la hiérarchie des images dans le paramètre : ".
|
|
|
31 |
"[cel] chemin_images";
|
|
|
32 |
throw new Exception($message, E_USER_ERROR);
|
|
|
33 |
}
|
|
|
34 |
return 'OK';
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
private function extraireMetadonneesExifTool($cheminImage) {
|
|
|
38 |
$metadata = array();
|
|
|
39 |
$res = exec('/usr/bin/exiftool -g -D '.$chemin_image, $metadata);
|
|
|
40 |
|
|
|
41 |
$metadata_decodees = array();
|
|
|
42 |
|
|
|
43 |
$categorie = '';
|
|
|
44 |
foreach($metadata as &$data) {
|
|
|
45 |
if($this->estUnSeparateurCategorieExifTool($data)) {
|
|
|
46 |
$categorie = trim(str_replace('----','',$data));
|
|
|
47 |
} else {
|
|
|
48 |
$data_decodee = $this->parserValeurMetadonneeExifTool($data);
|
|
|
49 |
$cle_metadonnee = str_replace(' ', '', $data_decodee['cle']);
|
|
|
50 |
$metadata_decodees[$categorie][$cle_metadonnee] = $data_decodee;
|
|
|
51 |
$this->id_cle_metadonnees[$cle_metadonnee] = $data_decodee['id'];
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
return $metadata_decodees;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function obtenirCheminImageOriginale($id_image) {
|
|
|
59 |
$nom = $this->convertirIdBddVersNomFichier($id_image, 'O');
|
|
|
60 |
$dossier = $this->obtenirDossierPourFormat($id_image,'O');
|
|
|
61 |
return $dossier.'/'.$nom;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
|
|
|
65 |
$id_avec_zeros = sprintf('%09s', $id) ;
|
|
|
66 |
$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
|
|
|
67 |
$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
|
|
|
68 |
return $nom_fichier;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public function obtenirDossierPourFormat($id, $format) {
|
|
|
72 |
$chemin_base = $this->config['cel']['chemin_images'];
|
|
|
73 |
$chemin_sur_serveur = $chemin_base;
|
|
|
74 |
|
|
|
75 |
$id = sprintf('%09s', $id);
|
|
|
76 |
$id = wordwrap($id, 3 , '_', true);
|
|
|
77 |
list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);
|
|
|
78 |
|
|
|
79 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
|
|
|
80 |
return $chemin_sur_serveur_final;
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
?>
|