Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 668 Rev 672
Line 1... Line 1...
1
<?php
1
<?php
2
Class ImageRecreation {
2
Class ImageRecreation {
Line 3... Line 3...
3
	
3
	
4
	private $droits = 0755;
4
	private $droits = 0705;
5
	private $formats = array('CRX2S','CXS','CS','CRS','XS','S','M','L','XL','X2L','X3L');
5
	private $formats = array('CRX2S','CXS','CS','CRS','XS','S','M','L','XL','X2L','X3L');
6
	const MODE_GD = 'gd';
6
	const MODE_GD = 'gd';
7
	const MODE_IMAGEMAGICK = 'imagemagick';
7
	const MODE_IMAGEMAGICK = 'imagemagick';
Line 8... Line 8...
8
	private $mode;
8
	private $mode;
Line 9... Line 9...
9
	
9
	
10
	private $verbose = true;
-
 
11
 
10
	private $verbose = true;
12
	public function ImageRecreation($config) {
11
 
Line 13... Line 12...
13
 
12
	public function __construct($config) {
14
		$this->config=$config;
13
		$this->config = $config;
15
		$this->mode = self::MODE_GD;
14
		$this->mode = self::MODE_GD;
16
		
15
		
17
		if (extension_loaded('imagick')) {
16
		if (extension_loaded('imagick')) {
Line 18... Line 17...
18
			putenv("MAGICK_TEMPORARY_PATH=".$this->config['cel_db']['chemin_stockage_temp']);
17
			putenv('MAGICK_TEMPORARY_PATH='.$this->config['cel_db']['chemin_stockage_temp']);
19
			$this->mode = self::MODE_IMAGEMAGICK;
18
			$this->mode = self::MODE_IMAGEMAGICK;
20
		}
19
		}
Line 21... Line 20...
21
	}
20
	}
22
	
-
 
23
	public function recreerMiniaturesRecursivement() {
21
	
24
		$this->itererRecursivement($this->config['cel_db']['chemin_images']);
22
	public function recreerMiniaturesRecursivement() {
Line 25... Line 23...
25
	}
23
		$this->itererRecursivement($this->config['cel_db']['chemin_images']);
26
	
-
 
27
	public function regenererMiniaturesIntervalle($params) {
24
	}
28
		
-
 
29
		$id_debut = $params[0];
25
	
30
		$id_fin = $params[1];
26
	public function regenererMiniaturesIntervalle($params) {
31
 
27
		$id_debut = $params[0];
32
		if (is_numeric($id_debut) && is_numeric($id_fin)) {
28
		$id_fin = $params[1];
33
			
29
 
Line 34... Line 30...
34
			for ($i = $id_debut; $i <= $id_fin; $i++) {;
30
		if (is_numeric($id_debut) && is_numeric($id_fin)) {
35
				
-
 
36
			    $tab_param = array($i);
31
			for ($i = $id_debut; $i <= $id_fin; $i++) {;
Line 37... Line 32...
37
			    $this->regenererMiniaturesPourId($tab_param);
32
			    $tab_param = array($i);
38
			}
33
			    $this->regenererMiniaturesPourId($tab_param);
39
		}
34
			}
Line 62... Line 57...
62
			
57
			
63
		}
58
		}
Line 64... Line 59...
64
	}
59
	}
65
	
-
 
66
	public function itererRecursivement($dossier) {
60
	
67
		
61
	public function itererRecursivement($dossier) {
Line 68... Line 62...
68
		// on ne parse que le dossier des images originales
62
		// on ne parse que le dossier des images originales
69
		$dossiers_a_exclure = $this->getFormats();
-
 
70
				
63
		$dossiers_a_exclure = $this->getFormats();
71
		foreach (new DirectoryIterator($dossier) as $fichier_ou_dossier) {
64
				
72
							
65
		foreach (new DirectoryIterator($dossier) as $fichier_ou_dossier) {
Line 73... Line 66...
73
			if ($fichier_ou_dossier->isDot()) {
66
			if ($fichier_ou_dossier->isDot()) {
74
				continue;
67
				continue;
75
			}
68
			}
Line 76... Line 69...
76
			
69
			
77
			if (in_array($fichier_ou_dossier->getBasename(), $dossiers_a_exclure)) {
-
 
78
				continue;
70
			if (in_array($fichier_ou_dossier->getBasename(), $dossiers_a_exclure)) {
79
			}
-
 
80
			
71
				continue;
81
		    if ($fichier_ou_dossier->isDir()) {
-
 
82
		    	
72
			}
Line 83... Line 73...
83
	    		$this->itererRecursivement($fichier_ou_dossier->getPathname());
73
			
84
	    		
74
		    if ($fichier_ou_dossier->isDir()) {
Line 85... Line 75...
85
		    } else {	
75
	    		$this->itererRecursivement($fichier_ou_dossier->getPathname());
86
		    	    	
76
		    } else {	
87
		    	$nom_fichier = $fichier_ou_dossier->getFilename();
-
 
88
		    	
77
		    	$nom_fichier = $fichier_ou_dossier->getFilename();
89
				$infos_image_originale = $this->obtenirImageEtInfosPourChemin($fichier_ou_dossier->getPathname());
78
		    	
90
		    	$id = $this->convertirBaseNomFichierVersIdBdd($nom_fichier, $this->formats);
79
				$infos_image_originale = $this->obtenirImageEtInfosPourChemin($fichier_ou_dossier->getPathname());
91
				
80
		    	$id = $this->convertirBaseNomFichierVersIdBdd($nom_fichier, $this->formats);
92
		    	// creation de miniatures pour chacuns des formats définis
81
				
Line 93... Line 82...
93
				foreach($this->formats as $format) {
82
		    	// creation de miniatures pour chacuns des formats définis
94
					
-
 
95
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
83
				foreach($this->formats as $format) {
96
				}
84
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
97
		    }
85
				}
Line 98... Line 86...
98
		}
86
		    }
99
	}
87
		}
100
	
-
 
101
	public function creerMiniatureImageSelonFormat($infos_image_originale, $format = 'O') {
88
	}
102
		
89
	
103
		if ($format == 'O') {		
90
	public function creerMiniatureImageSelonFormat($infos_image_originale, $format = 'O') {
104
			// format original : rien à faire
91
		if ($format == 'O') {		
105
			$image_redimensionnee = $infos_image_originale['image'];
92
			// format original : rien à faire
Line 127... Line 114...
127
		
114
		
128
		return $image_redimensionnee;
115
		return $image_redimensionnee;
Line 129... Line 116...
129
	}
116
	}
130
			
-
 
131
	public function creerEtStockerMiniatureFichierImageSelonFormat($id ,$infos_image_originale, $format = 'O') {
117
			
Line 132... Line 118...
132
		
118
	public function creerEtStockerMiniatureFichierImageSelonFormat($id ,$infos_image_originale, $format = 'O') {
133
		$image_redimensionnee = $this->creerMiniatureImageSelonFormat($infos_image_originale, $format);
119
		$image_redimensionnee = $this->creerMiniatureImageSelonFormat($infos_image_originale, $format);
Line 134... Line 120...
134
				
120
				
135
		$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
121
		$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
Line 136... Line 122...
136
		$this->ecrireImageSurDisque($image_redimensionnee, $id, $format, $taux_compression);
122
		$this->ecrireImageSurDisque($image_redimensionnee, $id, $format, $taux_compression);
137
				
-
 
138
		return true;
123
				
Line 139... Line 124...
139
	}
124
		return true;
140
	
125
	}
141
	public function creerImageRedimensionnee($infos_image_originale, $hauteur_redimension, $largeur_redimension) {
126
	
142
		
127
	public function creerImageRedimensionnee($infos_image_originale, $hauteur_redimension, $largeur_redimension) {
143
		$image_redimensionnee = imagecreatetruecolor($largeur_redimension, $hauteur_redimension);
128
		$image_redimensionnee = imagecreatetruecolor($largeur_redimension, $hauteur_redimension);
144
		
129
		
145
		imagecopyresampled($image_redimensionnee, 
130
		imagecopyresampled($image_redimensionnee, 
146
						$infos_image_originale['image'], 
131
			$infos_image_originale['image'], 
147
						0, 0, 
132
			0, 0, 
Line 148... Line 133...
148
						0, 0, 
133
			0, 0, 
149
						$largeur_redimension, 
134
			$largeur_redimension, 
Line 150... Line 135...
150
						$hauteur_redimension, 
135
			$hauteur_redimension, 
151
						$infos_image_originale['largeur'], 
-
 
152
						$infos_image_originale['hauteur']
136
			$infos_image_originale['largeur'], 
Line 153... Line 137...
153
		);
137
			$infos_image_originale['hauteur']
154
		
138
		);
Line 155... Line 139...
155
		return $image_redimensionnee;
139
		
156
	}
140
		return $image_redimensionnee;
Line 157... Line 141...
157
	
141
	}
158
	public function creerMiniature($informations_images, $format) {
-
 
159
				
142
	
160
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
143
	public function creerMiniature($informations_images, $format) {
Line 161... Line 144...
161
		
144
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
162
		$taille_image_redimensionnee = $this->calculerTailleImage($informations_images, $taille_reference_pour_format['hauteur']);
145
		
Line 163... Line 146...
163
		$image_redimensionnee = $this->creerImageRedimensionnee($informations_images, $taille_image_redimensionnee['hauteur'], $taille_image_redimensionnee['largeur']);
146
		$taille_image_redimensionnee = $this->calculerTailleImage($informations_images, $taille_reference_pour_format['hauteur']);
164
		
147
		$image_redimensionnee = $this->creerImageRedimensionnee($informations_images, $taille_image_redimensionnee['hauteur'], $taille_image_redimensionnee['largeur']);
165
		return $image_redimensionnee;
148
		
166
	}
149
		return $image_redimensionnee;
167
	
150
	}
168
	public function creerMiniatureCarree($informations_image, $format) {
151
	
169
		
152
	public function creerMiniatureCarree($informations_image, $format) {
Line 170... Line 153...
170
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
153
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
Line 171... Line 154...
171
		$cote_carre = $taille_reference_pour_format['largeur'];
154
		$cote_carre = $taille_reference_pour_format['largeur'];
172
		
155
		
173
		$image_redimensionnee_avec_rapport = $this->creerMiniature($informations_image, $format);
156
		$image_redimensionnee_avec_rapport = $this->creerMiniature($informations_image, $format);
174
		$taille_redimensionnee_avec_rapport = $this->calculerTailleImage($informations_image, $taille_reference_pour_format['hauteur']);
157
		$taille_redimensionnee_avec_rapport = $this->calculerTailleImage($informations_image, $taille_reference_pour_format['hauteur']);
Line 175... Line 158...
175
		
158
		
176
		if ($this->estPaysage($informations_image)) {				
159
		if ($this->estPaysage($informations_image)) {				
Line 177... Line 160...
177
				$debut_largeur_a_copier = 0 ;
160
			$debut_largeur_a_copier = 0 ;
178
				$debut_hauteur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['hauteur'])/2 ;	
-
 
179
		} else {
161
			$debut_hauteur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['hauteur'])/2 ;	
180
				$debut_largeur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['largeur'])/2 ;
162
		} else {
181
				$debut_hauteur_a_copier = 0 ;	
163
			$debut_largeur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['largeur'])/2 ;
Line 182... Line 164...
182
		}
164
			$debut_hauteur_a_copier = 0 ;	
183
		
165
		}
184
		$image_carre_blanc_cible = $this->renvoyerEtCreerImageCarreeBlancheSelonFormat($cote_carre);
166
		
185
		
167
		$image_carre_blanc_cible = $this->renvoyerEtCreerImageCarreeBlancheSelonFormat($cote_carre);
186
		imagecopy($image_carre_blanc_cible, $image_redimensionnee_avec_rapport,
168
		
187
				$debut_largeur_a_copier ,$debut_hauteur_a_copier, 0, 0,
169
		imagecopy($image_carre_blanc_cible, $image_redimensionnee_avec_rapport,
188
				$taille_redimensionnee_avec_rapport['largeur'], $taille_redimensionnee_avec_rapport['hauteur']
170
			$debut_largeur_a_copier ,$debut_hauteur_a_copier, 0, 0,
189
		);
171
			$taille_redimensionnee_avec_rapport['largeur'], $taille_redimensionnee_avec_rapport['hauteur']
190
 
172
		);
191
		return $image_carre_blanc_cible;
173
 
192
	}
174
		return $image_carre_blanc_cible;
193
	
175
	}
194
	public function creerMiniatureCarreeRognee($informations_image, $format) {
176
	
195
		
177
	public function creerMiniatureCarreeRognee($informations_image, $format) {
196
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
178
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
197
		$cote_carre = $taille_reference_pour_format['largeur'];
179
		$cote_carre = $taille_reference_pour_format['largeur'];
198
		$cote_carre_non_redimensionne = 0;
180
		$cote_carre_non_redimensionne = 0;
199
		
181
		
200
		if ($this->estPaysage($informations_image)) {	
182
		if ($this->estPaysage($informations_image)) {	
201
				$cote_carre_non_redimensionne = $informations_image['hauteur'];		
183
			$cote_carre_non_redimensionne = $informations_image['hauteur'];		
202
				$debut_largeur_a_copier = ($informations_image['hauteur'] - $cote_carre)/2 ;
184
			$debut_largeur_a_copier = ($informations_image['hauteur'] - $cote_carre)/2 ;
203
				$debut_hauteur_a_copier = 0;
185
			$debut_hauteur_a_copier = 0;
204
				
186
			
Line 205... Line 187...
205
				if($debut_largeur_a_copier <= 0) {
187
			if($debut_largeur_a_copier <= 0) {
Line 206... Line 188...
206
					$debut_largeur_a_copier = 0;
188
				$debut_largeur_a_copier = 0;
207
				}
189
			}
208
				
190
			
209
				$nb_pixels_largeur_a_copier = $cote_carre_non_redimensionne;
191
			$nb_pixels_largeur_a_copier = $cote_carre_non_redimensionne;
210
				$nb_pixels_hauteur_a_copier = $cote_carre_non_redimensionne;
192
			$nb_pixels_hauteur_a_copier = $cote_carre_non_redimensionne;
211
		} else {
193
		} else {
212
				$cote_carre_non_redimensionne = $informations_image['largeur'];
194
			$cote_carre_non_redimensionne = $informations_image['largeur'];
213
				$debut_largeur_a_copier = 0 ;
195
			$debut_largeur_a_copier = 0 ;
214
				$debut_hauteur_a_copier = ($informations_image['largeur'] - $cote_carre)/2;
196
			$debut_hauteur_a_copier = ($informations_image['largeur'] - $cote_carre)/2;
215
				
197
			
Line 216... Line 198...
216
				if($debut_hauteur_a_copier <= 0) {
198
			if($debut_hauteur_a_copier <= 0) {
Line 217... Line 199...
217
					$debut_hauteur_a_copier = 0;
199
				$debut_hauteur_a_copier = 0;
218
				}
200
			}
219
				
201
			
220
				$nb_pixels_largeur_a_copier = $cote_carre_non_redimensionne;
202
			$nb_pixels_largeur_a_copier = $cote_carre_non_redimensionne;
221
				$nb_pixels_hauteur_a_copier = $cote_carre_non_redimensionne;
203
			$nb_pixels_hauteur_a_copier = $cote_carre_non_redimensionne;
222
		}
204
		}
223
		
205
		
224
		$image_carre_temporaire = imagecreatetruecolor($cote_carre_non_redimensionne, $cote_carre_non_redimensionne);
206
		$image_carre_temporaire = imagecreatetruecolor($cote_carre_non_redimensionne, $cote_carre_non_redimensionne);
225
		
207
		
Line 226... Line 208...
226
		imagecopyresampled($image_carre_temporaire, 
208
		imagecopyresampled($image_carre_temporaire, 
227
						$informations_image['image'], 
209
			$informations_image['image'], 
Line 228... Line 210...
228
						0, 0, 
210
			0, 0, 
229
						$debut_largeur_a_copier,
-
 
230
						$debut_hauteur_a_copier, 
211
			$debut_largeur_a_copier,
231
						$cote_carre_non_redimensionne, 
212
			$debut_hauteur_a_copier, 
Line 232... Line 213...
232
						$cote_carre_non_redimensionne, 
213
			$cote_carre_non_redimensionne, 
Line 284... Line 265...
284
  			return false ;
265
  			return false ;
285
		}
266
		}
286
	}
267
	}
Line 287... Line 268...
287
	
268
	
288
	public function stockerImageExterne($chemin_fichier_temp, $chemin_destination) {
-
 
289
		
269
	public function stockerImageExterne($chemin_fichier_temp, $chemin_destination) {
290
		if(is_uploaded_file($chemin_fichier_temp)) {
270
		if(is_uploaded_file($chemin_fichier_temp)) {
291
			$deplacement = move_uploaded_file($chemin_fichier_temp, $chemin_destination);
271
			$deplacement = move_uploaded_file($chemin_fichier_temp, $chemin_destination);
292
		} else {
272
		} else {
293
			$deplacement = rename($chemin_fichier_temp, $chemin_destination);
273
			$deplacement = rename($chemin_fichier_temp, $chemin_destination);
Line 294... Line 274...
294
		}
274
		}
295
		
275
		
Line 296... Line 276...
296
		return $deplacement;
276
		return $deplacement;
-
 
277
	}
Line 297... Line -...
297
	}
-
 
298
	
-
 
299
	public function creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, $format) {
278
	
300
		
-
 
301
		$chemin_sur_serveur_final = $this->obtenirDossierPourFormat($id,$format);
279
	public function creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, $format) {
302
		
280
		$chemin_sur_serveur_final = $this->obtenirDossierPourFormat($id, $format);
303
		if (!file_exists($chemin_sur_serveur_final))
-
 
304
		{
-
 
305
			umask(0);
-
 
306
			if (mkdir($chemin_sur_serveur_final,$this->droits, true)) {
-
 
307
				chmod($chemin_sur_serveur_final,$this->droits);
281
		
308
			}
-
 
309
			else
282
		if (!file_exists($chemin_sur_serveur_final)) {
310
			{
283
			umask(0);
311
				$erreur =  'ERROR : probleme durant l\'écriture du dossier '.$format.' \n' ;
284
			if (!mkdir($chemin_sur_serveur_final, $this->droits, true)) {
312
				echo $erreur;
285
				$erreur =  'ERROR : probleme durant l\'écriture du dossier '.$format.' \n' ;
Line 313... Line 286...
313
				$this->logger('CEL_bugs',$erreur);
286
				$this->logger('CEL_bugs', $erreur);
314
				return false;
287
				return false;
Line 315... Line 288...
315
			}
288
			}
316
		}
-
 
317
		
289
		}
Line 318... Line 290...
318
		return $chemin_sur_serveur_final;
290
		
Line 319... Line 291...
319
	}
291
		return $chemin_sur_serveur_final;
320
	
292
	}
Line 321... Line 293...
321
	public function obtenirDossierPourFormat($id, $format) {
293
	
Line 322... Line -...
322
		
-
 
323
		$chemin_base = $this->config['cel_db']['chemin_images'];
-
 
324
	
-
 
325
		$chemin_sur_serveur = $chemin_base ;
294
	public function obtenirDossierPourFormat($id, $format) {
Line 326... Line 295...
326
	
295
		$chemin_base = $this->config['cel_db']['chemin_images'];
327
		$id = sprintf('%09s', $id) ;
296
	
Line 328... Line 297...
328
		$id = wordwrap($id, 3 , '_', true) ;
297
		$chemin_sur_serveur = $chemin_base;
329
	
-
 
330
		$niveauDossier = split("_", $id) ;
298
	
331
	
299
		$id = sprintf('%09s', $id);
Line 332... Line 300...
332
		$dossierNiveau1 = $niveauDossier[0] ;
300
		$id = wordwrap($id, 3 , '_', true);
333
		$dossierNiveau2 = $niveauDossier[1] ;
301
	
Line 334... Line 302...
334
		
302
		list($dossierNiveau1, $dossierNiveau2) = explode('_', $id);
335
		$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
-
 
336
		
303
	
337
		return $chemin_sur_serveur_final;
304
		$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
338
	}
305
		
Line 339... Line 306...
339
	
306
		return $chemin_sur_serveur_final;
340
	public function obtenirCheminImageOriginale($id_image) {
-
 
341
		
307
	}
Line 342... Line 308...
342
		$nom = $this->convertirIdBddVersNomFichier($id_image, 'O');
308
	
343
		$dossier = $this->obtenirDossierPourFormat($id_image,'O');
-
 
344
		
309
	public function obtenirCheminImageOriginale($id_image) {
345
		return $dossier.'/'.$nom;
310
		$nom = $this->convertirIdBddVersNomFichier($id_image, 'O');
346
	}
311
		$dossier = $this->obtenirDossierPourFormat($id_image,'O');
347
	
312
		
348
	public function obtenirImageEtInfosPourId($id_image) {
313
		return $dossier.'/'.$nom;
Line 366... Line 331...
366
		
331
		
367
		return $image_et_infos;
332
		return $image_et_infos;
Line 368... Line 333...
368
	}
333
	}
369
	
-
 
370
	public function obtenirDimensionsPourFormat($format) {
334
	
371
		
335
	public function obtenirDimensionsPourFormat($format) {
372
		$dimensions = array('largeur' => 0, 'hauteur' => 0);
336
		$dimensions = array('largeur' => 0, 'hauteur' => 0);
373
			
-
 
374
		if (isset($this->config['cel_db']['format_'.$format])) {
337
		
375
			
-
 
376
			$format_largeur_hauteur = split('_', $this->config['cel_db']['format_'.$format]);
-
 
377
			
-
 
378
			$dimensions['largeur'] = $format_largeur_hauteur[0];
338
		if (isset($this->config['cel_db']['format_'.$format])) {
Line 379... Line 339...
379
			$dimensions['hauteur'] = $format_largeur_hauteur[1];
339
			list($dimensions['largeur'], $dimensions['hauteur']) = explode('_', $this->config['cel_db']['format_'.$format]);
380
		}
-
 
381
		
340
		}
Line 382... Line 341...
382
		return $dimensions;
341
		
-
 
342
		return $dimensions;
383
		
343
	}
-
 
344
	
-
 
345
	public function calculerTailleImage($informations_images, $taille_max) {
384
	}
346
        $HL_redimension = array();
-
 
347
        
Line 385... Line -...
385
	
-
 
386
	public function calculerTailleImage($informations_images, $taille_max) {
-
 
387
	
-
 
388
	        $HL_redimension = array();
-
 
389
	        
-
 
390
	        if ($this->estPaysage($informations_images)) {
-
 
391
	        
348
        if ($this->estPaysage($informations_images)) {
392
		        $rapport = $informations_images['hauteur']/$informations_images['largeur'] ;
349
	        $rapport = $informations_images['hauteur']/$informations_images['largeur'] ;
393
		        $HL_redimension['largeur'] = round($taille_max) ;
350
	        $HL_redimension['largeur'] = round($taille_max) ;
394
		        $HL_redimension['hauteur'] = round($taille_max*$rapport) ;
351
	        $HL_redimension['hauteur'] = round($taille_max*$rapport) ;
395
		        
352
	        
396
	        } else {
353
        } else {
397
	        	$rapport = $informations_images['largeur']/$informations_images['hauteur'] ;
354
        	$rapport = $informations_images['largeur']/$informations_images['hauteur'] ;
398
		        $HL_redimension['hauteur'] = round($taille_max) ;
355
	        $HL_redimension['hauteur'] = round($taille_max) ;
Line 399... Line 356...
399
		        $HL_redimension['largeur'] = round($taille_max*$rapport) ;
356
	        $HL_redimension['largeur'] = round($taille_max*$rapport) ;
400
	        }
357
        }
401
	        
358
        
Line 402... Line 359...
402
	        return $HL_redimension;
359
        return $HL_redimension;
403
	}
-
 
404
	
360
	}
405
	public function getFormats() {
361
	
Line 406... Line 362...
406
		return $this->formats;
362
	public function getFormats() {
407
	}
-
 
408
	
363
		return $this->formats;
409
	public function estUnFormatCarre($format) {
364
	}
Line 410... Line 365...
410
		
365
	
411
		return (strpos($format,'C') === 0);		
366
	public function estUnFormatCarre($format) {
Line 423... Line 378...
423
	public function estPortait($informations_images) {
378
	public function estPortait($informations_images) {
424
		return $informations_images['largeur'] < $informations_images['hauteur'];
379
		return $informations_images['largeur'] < $informations_images['hauteur'];
425
	}
380
	}
Line 426... Line 381...
426
	
381
	
427
	public function renvoyerTauxCompressionPourPoids($poids_octets) {
-
 
428
 
382
	public function renvoyerTauxCompressionPourPoids($poids_octets) {
Line 429... Line 383...
429
		$poids_max_octets = $this->config['cel_db']['taille_max'];
383
		$poids_max_octets = $this->config['cel_db']['taille_max'];
Line 430... Line 384...
430
		
384
		
Line 436... Line 390...
436
	    
390
	    
437
	    return $ratio_compression;
391
	    return $ratio_compression;
Line 438... Line 392...
438
	}
392
	}
439
	
-
 
440
	public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
393
	
441
		
394
	public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
442
			// creation du format original
395
		// creation du format original
Line 443... Line 396...
443
		$id_avec_zeros = sprintf('%09s', $id) ;
396
		$id_avec_zeros = sprintf('%09s', $id) ;
Line 444... Line 397...
444
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
397
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
445
		
398
		
Line 446... Line 399...
446
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
399
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
447
		
-
 
448
		return $nom_fichier;
400
		
Line 449... Line 401...
449
	}
401
		return $nom_fichier;
450
	
402
	}
451
	public function convertirBaseNomFichierVersIdBdd($nom_fichier, $formats) {
403
	
Line 463... Line 415...
463
		
415
		
464
		return $id_image;
416
		return $id_image;
Line 465... Line 417...
465
	}
417
	}
466
	
-
 
467
	public function ecrireImageSurDisque($image_binaire, $id, $format, $compression = 100) {
418
	
Line 468... Line 419...
468
		
419
	public function ecrireImageSurDisque($image_binaire, $id, $format, $compression = 100) {
469
		umask(0);
420
		umask(0);
Line 479... Line 430...
479
		imagejpeg($image_binaire, $chemin_sur_serveur_final.'/'.$nom_fichier, $compression);
430
		imagejpeg($image_binaire, $chemin_sur_serveur_final.'/'.$nom_fichier, $compression);
480
		chmod($chemin_sur_serveur_final.'/'.$nom_fichier,$this->droits);
431
		chmod($chemin_sur_serveur_final.'/'.$nom_fichier,$this->droits);
481
	}
432
	}
Line 482... Line 433...
482
		
433
		
483
	public function ecrireImageSurDisqueAvecMeta($image_a_stocker, $compression = 100) {
-
 
484
 
434
	public function ecrireImageSurDisqueAvecMeta($image_a_stocker, $compression = 100) {
Line 485... Line 435...
485
		$image_a_stocker = new Imagick($image_a_stocker);
435
		$image_a_stocker = new Imagick($image_a_stocker);
486
	
436
	
487
		// l'utilisation d'image magick préserve les métadonnées lors d'une recompression
437
		// l'utilisation d'image magick préserve les métadonnées lors d'une recompression
Line 493... Line 443...
493
		
443
		
494
		chmod($image_a_stocker,$this->droits);
444
		chmod($image_a_stocker,$this->droits);
Line 495... Line 445...
495
	}
445
	}
496
	
-
 
497
	public function renvoyerEtCreerImageCarreeBlancheSelonFormat($cote) {
446
	
498
		
447
	public function renvoyerEtCreerImageCarreeBlancheSelonFormat($cote) {
499
		$image_blanche = imagecreatetruecolor($cote, $cote);		
448
		$image_blanche = imagecreatetruecolor($cote, $cote);		
Line 500... Line 449...
500
		$blanc = imagecolorallocate($image_blanche, 255, 255, 255);
449
		$blanc = imagecolorallocate($image_blanche, 255, 255, 255);
Line 506... Line 455...
506
	public function detruireImageEnMemoire($image) {		
455
	public function detruireImageEnMemoire($image) {		
507
		imagedestroy($image);
456
		imagedestroy($image);
508
	}
457
	}
Line 509... Line 458...
509
	
458
	
510
	public function detruireImageSurDisque($id) {
-
 
511
		
459
	public function detruireImageSurDisque($id) {
Line 512... Line 460...
512
		$formats = $this->getFormats();
460
		$formats = $this->getFormats();
513
		
461
		
Line 539... Line 487...
539
	 * see documentation on how to tune the algorithm
487
	 * see documentation on how to tune the algorithm
540
	 *
488
	 *
541
	 * $informations_image - le tableau d'informations sur l'image tel que renvoyé par la fonction obtenirImageEtInfosPourChemin
489
	 * $informations_image - le tableau d'informations sur l'image tel que renvoyé par la fonction obtenirImageEtInfosPourChemin
542
	 * $format - le format (ex. : CS, XS, XL, CRS)
490
	 * $format - le format (ex. : CS, XS, XL, CRS)
543
	*/
491
	*/
544
	function opticrop($informations_image, $format) {
492
	public function opticrop($informations_image, $format) {
545
 
-
 
546
		umask(0);
493
		umask(0);
Line 547... Line 494...
547
		
494
		
548
		$nom_temp = md5(time());
495
		$nom_temp = md5(time());
Line 601... Line 548...
601
	    if ($largeur_image_originale/$hauteur_image_originale > $ar) {
548
	    if ($largeur_image_originale/$hauteur_image_originale > $ar) {
602
	        // source AR wider than target
549
	        // source AR wider than target
603
	        // crop width to target AR
550
	        // crop width to target AR
604
	        $wcrop0 = round($ar*$hauteur_image_originale);
551
	        $wcrop0 = round($ar*$hauteur_image_originale);
605
	        $hcrop0 = $hauteur_image_originale;
552
	        $hcrop0 = $hauteur_image_originale;
606
	    } 
-
 
607
	    else {
553
	    } else {
608
	        // crop height to target AR
554
	        // crop height to target AR
609
	        $wcrop0 = $largeur_image_originale;
555
	        $wcrop0 = $largeur_image_originale;
610
	        $hcrop0 = round($largeur_image_originale/$ar);
556
	        $hcrop0 = round($largeur_image_originale/$ar);
611
	    }
557
	    }
Line 685... Line 631...
685
	    $image_sortie = ImageCreateFromJpeg($out);
631
	    $image_sortie = ImageCreateFromJpeg($out);
686
	    unlink($out);
632
	    unlink($out);
Line 687... Line 633...
687
	    
633
	    
688
	    return $image_sortie;
634
	    return $image_sortie;
689
	}
-
 
690
	
635
	}
691
}
636
}
692
?>
637
?>