Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2134 Rev 2414
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
-
 
3
/**
2
// Cette classe est un quasi copier-coller de la classe éponyme dans 
4
 * Cette classe est un quasi copier-coller de la classe éponyme dans
3
// le dossier lib de jrest mais pas de mécanisme commun pour les classes
5
 * le dossier lib de jrest mais pas de mécanisme commun pour les classes
-
 
6
 *
-
 
7
 * @category   CEL
-
 
8
 * @package    Scripts
-
 
9
 * @subpackage Génération Images
-
 
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
-
 
11
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
12
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
-
 
13
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
-
 
14
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
-
 
15
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
-
 
16
 */
4
// TODO: utiliser la même classe pour jrest ainsi que les scripts
17
// TODO: utiliser la même classe pour jrest ainsi que les scripts => créer un projet cel-commun (même principe que del-commun)
5
Class ImageRecreation {
18
Class ImageRecreation {
Line 6... Line 19...
6
 
19
 
7
	private $droits = 0755;
20
	private $droits = 0755;
8
	private $formats = array('CRX2S','CRXS','CXS','CS','CRS','XS','S','M','L','XL','X2L','X3L');
21
	private $formats = array('CRX2S','CRXS','CXS','CS','CRS','XS','S','M','L','XL','X2L','X3L');
Line 28... Line 41...
28
		$id_debut = $params[0];
41
		$id_debut = $params[0];
29
		$id_fin = $params[1];
42
		$id_fin = $params[1];
Line 30... Line 43...
30
 
43
 
31
		if (is_numeric($id_debut) && is_numeric($id_fin)) {
44
		if (is_numeric($id_debut) && is_numeric($id_fin)) {
32
			for ($i = $id_debut; $i <= $id_fin; $i++) {;
45
			for ($i = $id_debut; $i <= $id_fin; $i++) {;
33
			    $tab_param = array($i);
46
				$tab_param = array($i);
34
			    $this->regenererMiniaturesPourId($tab_param);
47
				$this->regenererMiniaturesPourId($tab_param);
35
			}
48
			}
36
		}
49
		}
Line 37... Line 50...
37
	}
50
	}
Line 74... Line 87...
74
 
87
 
75
			if (in_array($fichier_ou_dossier->getBasename(), $dossiers_a_exclure)) {
88
			if (in_array($fichier_ou_dossier->getBasename(), $dossiers_a_exclure)) {
76
				continue;
89
				continue;
Line 77... Line 90...
77
			}
90
			}
78
 
91
 
79
		    if ($fichier_ou_dossier->isDir()) {
92
			if ($fichier_ou_dossier->isDir()) {
80
	    		$this->itererRecursivement($fichier_ou_dossier->getPathname());
93
				$this->itererRecursivement($fichier_ou_dossier->getPathname());
Line 81... Line 94...
81
		    } else {
94
			} else {
82
		    	$nom_fichier = $fichier_ou_dossier->getFilename();
95
				$nom_fichier = $fichier_ou_dossier->getFilename();
Line 83... Line 96...
83
 
96
 
84
				$infos_image_originale = $this->obtenirImageEtInfosPourChemin($fichier_ou_dossier->getPathname());
97
				$infos_image_originale = $this->obtenirImageEtInfosPourChemin($fichier_ou_dossier->getPathname());
85
		    	$id = $this->convertirBaseNomFichierVersIdBdd($nom_fichier, $this->formats);
98
				$id = $this->convertirBaseNomFichierVersIdBdd($nom_fichier, $this->formats);
86
 
99
 
87
		    	// creation de miniatures pour chacuns des formats définis
100
				// creation de miniatures pour chacuns des formats définis
88
				foreach ($this->formats as $format) {
101
				foreach ($this->formats as $format) {
89
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
102
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
90
				}
103
				}
91
		    }
104
			}
92
		}
105
		}
93
	}
106
	}
94
	
107
 
Line 95... Line 108...
95
	public function creerOuRenvoyerImage($id, $format) {
108
	public function creerOuRenvoyerImage($id, $format) {
96
		$dossier = $this->obtenirDossierPourFormat($id, $format);
109
		$dossier = $this->obtenirDossierPourFormat($id, $format);
97
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
110
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
98
		$chemin_image = $dossier.'/'.$nom_fichier;	
111
		$chemin_image = $dossier.'/'.$nom_fichier;
99
 
112
 
100
		$image = false;
113
		$image = false;
101
		if(!file_exists($chemin_image)) {
114
		if(!file_exists($chemin_image)) {
102
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($this->obtenirCheminImageOriginale($id));
115
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($this->obtenirCheminImageOriginale($id));
103
			if($infos_image_originale) {
116
			if($infos_image_originale) {
104
				$debut = microtime();
117
				$debut = microtime();
105
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
118
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
106
				
119
 
107
				$image = file_get_contents($chemin_image);
120
				$image = file_get_contents($chemin_image);
108
			}
121
			}
109
		} else {
122
		} else {
Line 110... Line 123...
110
			$image = file_get_contents($chemin_image);
123
			$image = file_get_contents($chemin_image);
111
		}
124
		}
Line 138... Line 151...
138
			}
151
			}
139
		}
152
		}
Line 140... Line 153...
140
 
153
 
141
		return $image_redimensionnee;
154
		return $image_redimensionnee;
142
	}
155
	}
143
	
156
 
144
	public function stockerFichierOriginal($fichier, $id) {
157
	public function stockerFichierOriginal($fichier, $id) {
145
		$chemin_fichier_origine = is_array($fichier) ? $fichier['tmp_name'] : $fichier;
158
		$chemin_fichier_origine = is_array($fichier) ? $fichier['tmp_name'] : $fichier;
146
		
159
 
147
		$chemin_base_fichier = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, 'O');
160
		$chemin_base_fichier = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, 'O');
148
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
161
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
149
		
162
 
150
		$chemin_fichier = $chemin_base_fichier.'/'.$nom_fichier;
163
		$chemin_fichier = $chemin_base_fichier.'/'.$nom_fichier;
151
		
164
 
152
		$deplacement_fichier = $this->stockerImageExterne($chemin_fichier_origine, $chemin_fichier);
165
		$deplacement_fichier = $this->stockerImageExterne($chemin_fichier_origine, $chemin_fichier);
153
		
166
 
154
		if ($deplacement_fichier) {
167
		if ($deplacement_fichier) {
155
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
168
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
156
			$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
169
			$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
157
		
170
 
158
			if ($taux_compression < 100 && $this->mode == self::MODE_IMAGEMAGICK) {
171
			if ($taux_compression < 100 && $this->mode == self::MODE_IMAGEMAGICK) {
159
				$this->ecrireImageSurDisqueAvecMeta($chemin_fichier, $taux_compression);
172
				$this->ecrireImageSurDisqueAvecMeta($chemin_fichier, $taux_compression);
Line 160... Line 173...
160
			}
173
			}
161
 
174
 
162
			return $infos_image_originale;
175
			return $infos_image_originale;
163
		
176
 
164
		} else {
177
		} else {
165
			$erreur =  'ERROR : probleme durant le déplacement du fichier temporaire \n' ;
178
			$erreur =  'ERROR : probleme durant le déplacement du fichier temporaire \n' ;
166
			$this->logger('CEL_bugs',$erreur);
179
			$this->logger('CEL_bugs',$erreur);
167
			return false ;
180
			return false ;
168
		}
181
		}
169
	}
182
	}
170
	
183
 
171
	public function stockerFichierEtCreerMiniatures($fichier, $id) {
184
	public function stockerFichierEtCreerMiniatures($fichier, $id) {
172
		
185
 
173
		$infos_image_originale_stockee = $this->stockerFichierOriginal($fichier, $id);
186
		$infos_image_originale_stockee = $this->stockerFichierOriginal($fichier, $id);
174
		if($infos_image_originale_stockee) {
187
		if($infos_image_originale_stockee) {
175
			$formats = $this->getFormats();
188
			$formats = $this->getFormats();
176
	
189
 
177
			// creation de miniatures pour chacuns des formats définis
190
			// creation de miniatures pour chacuns des formats définis
178
			foreach($formats as $format) {
191
			foreach($formats as $format) {
179
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale_stockee, $format);
192
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale_stockee, $format);
180
			}
193
			}
181
		} else {
194
		} else {
182
			$erreur =  'ERROR : impossible d\'obtenir les informations sur l\'image originale \n' ;
195
			$erreur =  'ERROR : impossible d\'obtenir les informations sur l\'image originale \n' ;
183
			$this->logger('CEL_bugs',$erreur);
196
			$this->logger('CEL_bugs',$erreur);
184
			return false ;
197
			return false ;
185
		}
198
		}
186
	
199
 
Line 187... Line 200...
187
		return true ;
200
		return true ;
188
	}
201
	}
Line 265... Line 278...
265
		} else {
278
		} else {
266
			$cote_carre_non_redimensionne = $informations_image['largeur'];
279
			$cote_carre_non_redimensionne = $informations_image['largeur'];
267
			$debut_largeur_a_copier = 0 ;
280
			$debut_largeur_a_copier = 0 ;
268
			$debut_hauteur_a_copier = ($informations_image['largeur'] - $cote_carre)/2;
281
			$debut_hauteur_a_copier = ($informations_image['largeur'] - $cote_carre)/2;
Line 269... Line 282...
269
 
282
 
270
			if($debut_hauteur_a_copier <= 0) {
283
			if ($debut_hauteur_a_copier <= 0) {
271
				$debut_hauteur_a_copier = 0;
284
				$debut_hauteur_a_copier = 0;
Line 272... Line 285...
272
			}
285
			}
273
 
286
 
Line 378... Line 391...
378
 
391
 
379
		return $dimensions;
392
		return $dimensions;
Line 380... Line 393...
380
	}
393
	}
381
 
394
 
Line 382... Line 395...
382
	public function calculerTailleImage($informations_images, $taille_max) {
395
	public function calculerTailleImage($informations_images, $taille_max) {
383
        $HL_redimension = array();
396
		$HL_redimension = array();
384
 
397
 
385
        if ($this->estPaysage($informations_images)) {
398
		if ($this->estPaysage($informations_images)) {
386
	        $rapport = $informations_images['hauteur']/$informations_images['largeur'] ;
-
 
387
	        $HL_redimension['largeur'] = round($taille_max) ;
399
			$rapport = $informations_images['hauteur']/$informations_images['largeur'] ;
388
	        $HL_redimension['hauteur'] = round($taille_max*$rapport) ;
400
			$HL_redimension['largeur'] = round($taille_max) ;
389
 
401
			$HL_redimension['hauteur'] = round($taille_max*$rapport) ;
390
        } else {
402
		} else {
391
        	$rapport = $informations_images['largeur']/$informations_images['hauteur'] ;
403
			$rapport = $informations_images['largeur']/$informations_images['hauteur'] ;
Line 392... Line 404...
392
	        $HL_redimension['hauteur'] = round($taille_max) ;
404
			$HL_redimension['hauteur'] = round($taille_max) ;
393
	        $HL_redimension['largeur'] = round($taille_max*$rapport) ;
405
			$HL_redimension['largeur'] = round($taille_max*$rapport) ;
Line 394... Line 406...
394
        }
406
		}
395
 
407
 
396
        return $HL_redimension;
408
		return $HL_redimension;
Line 419... Line 431...
419
	public function renvoyerTauxCompressionPourPoids($poids_octets) {
431
	public function renvoyerTauxCompressionPourPoids($poids_octets) {
420
		$poids_max_octets = Config::get('tailleMaxImages');
432
		$poids_max_octets = Config::get('tailleMaxImages');
Line 421... Line 433...
421
 
433
 
Line 422... Line 434...
422
		$ratio_compression = 100 ;
434
		$ratio_compression = 100 ;
423
 
435
 
424
	    if ($poids_octets >= $poids_max_octets) {
436
		if ($poids_octets >= $poids_max_octets) {
Line 425... Line 437...
425
	      $ratio_compression = 75 ;
437
			$ratio_compression = 75 ;
426
	    }
438
		}
Line 427... Line 439...
427
 
439
 
428
	    return $ratio_compression;
440
		return $ratio_compression;
429
	}
441
	}
Line 537... Line 549...
537
		$dimension_vignettes = $this->obtenirDimensionsPourFormat($format);
549
		$dimension_vignettes = $this->obtenirDimensionsPourFormat($format);
Line 538... Line 550...
538
 
550
 
539
		$largeur_vignette = $dimension_vignettes['largeur'];
551
		$largeur_vignette = $dimension_vignettes['largeur'];
Line 665... Line 661...
665
	    $img->destroy();
661
		$img->destroy();
666
	    $imgcp->destroy();
662
		$imgcp->destroy();
Line 667... Line 663...
667
 
663
 
668
	    $image_sortie = ImageCreateFromJpeg($out);
664
		$image_sortie = ImageCreateFromJpeg($out);
669
	    unlink($out);
-
 
670
 
-
 
671
	    return $image_sortie;
665
		unlink($out);
-
 
666
 
672
	}
667
		return $image_sortie;