Subversion Repositories eFlore/Applications.cel

Rev

Rev 621 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 621 Rev 632
1
<?php
1
<?php
2
Class ImageRecreation extends DBAccessor {
2
Class ImageRecreation {
3
	
3
	
4
	private $droits = 0755;
4
	private $droits = 0755;
-
 
5
	private $formats = array('CRX2S','CXS','CS','CRS','XS','S','M','L','XL','X2L','X3L');
-
 
6
	const MODE_GD = 'gd';
-
 
7
	const MODE_IMAGEMAGICK = 'imagemagick';
-
 
8
	private $mode;
-
 
9
	
5
	private $formats = array('CRX2S','CXS','CS','S','M','L','XL','X2L','X3L');
10
	private $verbose = true;
6
 
11
 
7
	public function ImageRecreation($config) {
12
	public function ImageRecreation($config) {
8
 
13
 
9
		$this->config=$config;
14
		$this->config=$config;
-
 
15
		$this->mode = self::MODE_GD;
-
 
16
		
-
 
17
		if (extension_loaded('imagick')) {
-
 
18
			putenv("MAGICK_TEMPORARY_PATH=/home/aurelien/web/file_tmp");
-
 
19
			$this->mode = self::MODE_IMAGEMAGICK;
-
 
20
		}
10
	}
21
	}
-
 
22
	
-
 
23
	public function recreerMiniaturesRecursivement() {
-
 
24
		$this->itererRecursivement($this->config['cel_db']['chemin_images']);
-
 
25
	}
11
	
26
	
-
 
27
	public function testOptiCrop() {
-
 
28
		
-
 
29
		$image = $this->obtenirImageEtInfosPourChemin('/home/aurelien/web/file_tmp/test.jpg');
12
	public function getRessource() {
30
		return $this->opticrop($image,'CRXS','');
13
		
31
		
14
	}
32
	}
15
	
33
	
-
 
34
	public function regenererMiniaturesIntervalle($params) {
-
 
35
		
-
 
36
		$id_debut = $params[0];
-
 
37
		$id_fin = $params[1];
-
 
38
 
-
 
39
		if (is_numeric($id_debut) && is_numeric($id_fin)) {
-
 
40
			
-
 
41
			
-
 
42
			//echo("Début du traitement des images de ".$id_debut." à ".$id_fin."\n");
-
 
43
			
-
 
44
			for ($i = $id_debut; $i <= $id_fin; $i++) {
-
 
45
					
-
 
46
				echo($i."\n");
-
 
47
				
-
 
48
			    $tab_param = array($i);
-
 
49
			    $this->regenererMiniaturesPourId($tab_param);
16
	public function getElement($param) {
50
			}
17
		
51
		}
-
 
52
	}
-
 
53
	
-
 
54
	public function regenererMiniaturesPourId($params) {
-
 
55
 
-
 
56
		$id = $params[0];
-
 
57
 
-
 
58
		if (!is_numeric($id)) {
18
	}
59
		      return;
-
 
60
		}
-
 
61
 
-
 
62
		$dossier_fichier = $this->obtenirDossierPourFormat($id, 'O');
-
 
63
 
-
 
64
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
-
 
65
		
-
 
66
		$chemin_fichier = $dossier_fichier.'/'.$nom_fichier;
-
 
67
 
-
 
68
		if(file_exists($chemin_fichier)) {
-
 
69
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
-
 
70
							
-
 
71
			// creation de miniatures pour chacuns des formats définis
-
 
72
			foreach($this->formats as $format) {
-
 
73
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
-
 
74
			}
-
 
75
					      
-
 
76
	      	//if($this->verbose) {
-
 
77
	      		//echo("traitement de l'image ".$infos_image_originale."\n");
-
 
78
	      	//}
19
	
79
		} else {
20
	public function recreerMiniaturesRecursivement() {
80
			//echo 'le fichier '.$chemin_fichier.'n\'existe pas '."\n";
21
		$this->itererRecursivement($this->config['cel_db']['chemin_images']);
81
		}
22
	}
82
	}
23
	
83
	
24
	public function itererRecursivement($dossier) {
84
	public function itererRecursivement($dossier) {
25
		
85
		
26
		// on ne parse que le dossier des images originales
86
		// on ne parse que le dossier des images originales
27
		$dossiers_a_exclure = $this->getFormats();
87
		$dossiers_a_exclure = $this->getFormats();
28
				
88
				
29
		foreach (new DirectoryIterator($dossier) as $fichier_ou_dossier) {
89
		foreach (new DirectoryIterator($dossier) as $fichier_ou_dossier) {
30
							
90
							
31
			if($fichier_ou_dossier->isDot()) {
91
			if ($fichier_ou_dossier->isDot()) {
32
				continue;
92
				continue;
33
			}
93
			}
34
			
94
			
35
			if(in_array($fichier_ou_dossier->getBasename(), $dossiers_a_exclure)) {
95
			if (in_array($fichier_ou_dossier->getBasename(), $dossiers_a_exclure)) {
36
				continue;
96
				continue;
37
			}
97
			}
38
			
98
			
39
		    if($fichier_ou_dossier->isDir()) {
99
		    if ($fichier_ou_dossier->isDir()) {
40
		    	
100
		    	
41
		    	$profondeur_dossier_fils = $profondeur + 1;
101
		    	$profondeur_dossier_fils = $profondeur + 1;
42
	    		$this->itererRecursivement($fichier_ou_dossier->getPathname(), $profondeur_dossier_fils);
102
	    		$this->itererRecursivement($fichier_ou_dossier->getPathname(), $profondeur_dossier_fils);
43
	    		
103
	    		
44
		    } else {	
104
		    } else {	
45
		    	    	
105
		    	    	
46
		    	$nom_fichier = $fichier_ou_dossier->getFilename();
106
		    	$nom_fichier = $fichier_ou_dossier->getFilename();
47
		    	
107
		    	
48
				$infos_image_originale = $this->obtenirImageEtInfosPourChemin($fichier_ou_dossier->getPathname());
108
				$infos_image_originale = $this->obtenirImageEtInfosPourChemin($fichier_ou_dossier->getPathname());
49
		    	$id = $this->convertirBaseNomFichierVersIdBdd($nom_fichier, $this->formats);
109
		    	$id = $this->convertirBaseNomFichierVersIdBdd($nom_fichier, $this->formats);
50
				
110
				
51
		    	// creation de miniatures pour chacuns des formats définis
111
		    	// creation de miniatures pour chacuns des formats définis
52
				foreach($this->formats as $format) {
112
				foreach($this->formats as $format) {
53
					
113
					
54
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
114
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
55
				}
115
				}
56
		    }
116
		    }
57
		}
117
		}
58
	}
118
	}
59
			
119
			
60
	public function creerEtStockerMiniatureFichierImageSelonFormat($id ,$infos_image_originale, $format = 'O') {
120
	public function creerEtStockerMiniatureFichierImageSelonFormat($id ,$infos_image_originale, $format = 'O') {
61
		
121
		
62
		if($format == 'O') {		
122
		if ($format == 'O') {		
63
			// format original : rien à faire
123
			// format original : rien à faire
64
			$image_redimensionnee = $infos_image_originale['image'];
124
			$image_redimensionnee = $infos_image_originale['image'];
65
			
125
			
66
		} else {
126
		} else {
67
			 if($this->estUnFormatRogne($format)) {
127
			 if ($this->estUnFormatRogne($format)) {
-
 
128
			 	
-
 
129
			 	if ($this->mode == self::MODE_IMAGEMAGICK) {
-
 
130
			 		// si l'on dispose de la librairie imageMagick
-
 
131
			 		// on applique l'algorithme d'auto détection de sujets
-
 
132
			 		// qui centre la miniature sur le sujet de l'image
-
 
133
			 		$image_redimensionnee = $this->opticrop($infos_image_originale, $format);
-
 
134
			 	} else {
-
 
135
			 		// si l'on ne dispose que de gd
68
				// la minature est une image redimensionnée rognée au centre
136
					// la minature est une image redimensionnée rognée au centre
69
				$image_redimensionnee = $this->creerMiniatureCarreeRognee($infos_image_originale, $format); 														
137
					$image_redimensionnee = $this->creerMiniatureCarreeRognee($infos_image_originale, $format); 
-
 
138
			 	}	 	
70
			} else if($this->estUnFormatCarre($format)) {
139
			} else if ($this->estUnFormatCarre($format)) {
71
				// le format carre et une image redimensionnée en gardant son ratio, insérée dans un carré blanc
140
				// le format carre et une image redimensionnée en gardant son ratio, insérée dans un carré blanc
72
				$image_redimensionnee = $this->creerMiniatureCarree($infos_image_originale, $format);				
141
				$image_redimensionnee = $this->creerMiniatureCarree($infos_image_originale, $format);				
73
			} else {
142
			} else {
74
				$image_redimensionnee = $this->creerMiniature($infos_image_originale, $format);			
143
				$image_redimensionnee = $this->creerMiniature($infos_image_originale, $format);			
75
			}
144
			}
76
		}
145
		}
77
				
146
				
78
		$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
147
		$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
79
		$this->ecrireImageSurDisque($image_redimensionnee, $id, $format, $taux_compression);
148
		$this->ecrireImageSurDisque($image_redimensionnee, $id, $format, $taux_compression);
80
				
149
				
81
		return true;
150
		return true;
82
	}
151
	}
83
	
152
	
84
	public function creerImageRedimensionnee($infos_image_originale, $hauteur_redimension, $largeur_redimension) {
153
	public function creerImageRedimensionnee($infos_image_originale, $hauteur_redimension, $largeur_redimension) {
85
		
154
		
86
		$image_redimensionnee = imagecreatetruecolor($largeur_redimension, $hauteur_redimension);
155
		$image_redimensionnee = imagecreatetruecolor($largeur_redimension, $hauteur_redimension);
87
		
156
		
88
		imagecopyresampled($image_redimensionnee, 
157
		imagecopyresampled($image_redimensionnee, 
89
						$infos_image_originale['image'], 
158
						$infos_image_originale['image'], 
90
						0, 0, 
159
						0, 0, 
91
						0, 0, 
160
						0, 0, 
92
						$largeur_redimension, 
161
						$largeur_redimension, 
93
						$hauteur_redimension, 
162
						$hauteur_redimension, 
94
						$infos_image_originale['largeur'], 
163
						$infos_image_originale['largeur'], 
95
						$infos_image_originale['hauteur']
164
						$infos_image_originale['hauteur']
96
		);
165
		);
97
		
166
		
98
		return $image_redimensionnee;
167
		return $image_redimensionnee;
99
	}
168
	}
100
	
169
	
101
	public function creerMiniature($informations_images, $format) {
170
	public function creerMiniature($informations_images, $format) {
102
				
171
				
103
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
172
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
104
		
173
		
105
		$taille_image_redimensionnee = $this->calculerTailleImage($informations_images, $taille_reference_pour_format['hauteur']);
174
		$taille_image_redimensionnee = $this->calculerTailleImage($informations_images, $taille_reference_pour_format['hauteur']);
106
		$image_redimensionnee = $this->creerImageRedimensionnee($informations_images, $taille_image_redimensionnee['hauteur'], $taille_image_redimensionnee['largeur']);
175
		$image_redimensionnee = $this->creerImageRedimensionnee($informations_images, $taille_image_redimensionnee['hauteur'], $taille_image_redimensionnee['largeur']);
107
		
176
		
108
		return $image_redimensionnee;
177
		return $image_redimensionnee;
109
	}
178
	}
110
	
179
	
111
	public function creerMiniatureCarree($informations_image, $format) {
180
	public function creerMiniatureCarree($informations_image, $format) {
112
		
181
		
113
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
182
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
114
		$cote_carre = $taille_reference_pour_format['largeur'];
183
		$cote_carre = $taille_reference_pour_format['largeur'];
115
		
184
		
116
		$image_redimensionnee_avec_rapport = $this->creerMiniature($informations_image, $format);
185
		$image_redimensionnee_avec_rapport = $this->creerMiniature($informations_image, $format);
117
		$taille_redimensionnee_avec_rapport = $this->calculerTailleImage($informations_image, $taille_reference_pour_format['hauteur']);
186
		$taille_redimensionnee_avec_rapport = $this->calculerTailleImage($informations_image, $taille_reference_pour_format['hauteur']);
118
		
187
		
119
		if($this->estPaysage($informations_image)) {				
188
		if ($this->estPaysage($informations_image)) {				
120
				$debut_largeur_a_copier = 0 ;
189
				$debut_largeur_a_copier = 0 ;
121
				$debut_hauteur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['hauteur'])/2 ;	
190
				$debut_hauteur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['hauteur'])/2 ;	
122
		} else {
191
		} else {
123
				$debut_largeur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['largeur'])/2 ;
192
				$debut_largeur_a_copier = ($cote_carre - $taille_redimensionnee_avec_rapport['largeur'])/2 ;
124
				$debut_hauteur_a_copier = 0 ;	
193
				$debut_hauteur_a_copier = 0 ;	
125
		}
194
		}
126
		
195
		
127
		$image_carre_blanc_cible = $this->renvoyerEtCreerImageCarreeBlancheSelonFormat($cote_carre);
196
		$image_carre_blanc_cible = $this->renvoyerEtCreerImageCarreeBlancheSelonFormat($cote_carre);
128
		
197
		
129
		imagecopy($image_carre_blanc_cible, $image_redimensionnee_avec_rapport,
198
		imagecopy($image_carre_blanc_cible, $image_redimensionnee_avec_rapport,
130
				$debut_largeur_a_copier ,$debut_hauteur_a_copier, 0, 0,
199
				$debut_largeur_a_copier ,$debut_hauteur_a_copier, 0, 0,
131
				$taille_redimensionnee_avec_rapport['largeur'], $taille_redimensionnee_avec_rapport['hauteur']
200
				$taille_redimensionnee_avec_rapport['largeur'], $taille_redimensionnee_avec_rapport['hauteur']
132
		);
201
		);
133
 
202
 
134
		return $image_carre_blanc_cible;
203
		return $image_carre_blanc_cible;
135
	}
204
	}
136
	
205
	
137
	public function creerMiniatureCarreeRognee($informations_image, $format) {
206
	public function creerMiniatureCarreeRognee($informations_image, $format) {
138
		
207
		
139
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
208
		$taille_reference_pour_format = $this->obtenirDimensionsPourFormat($format);
140
		$cote_carre = $taille_reference_pour_format['largeur'];
209
		$cote_carre = $taille_reference_pour_format['largeur'];
141
		$cote_carre_non_redimensionne = 0;
210
		$cote_carre_non_redimensionne = 0;
142
		
211
		
143
		if($this->estPaysage($informations_image)) {	
212
		if ($this->estPaysage($informations_image)) {	
144
				$cote_carre_non_redimensionne = $informations_image['hauteur'];		
213
				$cote_carre_non_redimensionne = $informations_image['hauteur'];		
145
				$debut_largeur_a_copier = ($informations_image['hauteur'] - $informations_image['hauteur'])/2 ;
214
				$debut_largeur_a_copier = ($informations_image['hauteur'] - $informations_image['hauteur'])/2 ;
146
				$debut_hauteur_a_copier = 0;
215
				$debut_hauteur_a_copier = 0;
147
				$nb_pixels_largeur_a_copier = $informations_image['hauteur'];
216
				$nb_pixels_largeur_a_copier = $informations_image['hauteur'];
148
				$nb_pixels_hauteur_a_copier = $informations_image['hauteur'];
217
				$nb_pixels_hauteur_a_copier = $informations_image['hauteur'];
149
		} else {
218
		} else {
150
				$cote_carre_non_redimensionne = $informations_image['largeur'];
219
				$cote_carre_non_redimensionne = $informations_image['largeur'];
151
				$debut_largeur_a_copier = 0 ;
220
				$debut_largeur_a_copier = 0 ;
152
				$debut_hauteur_a_copier = ($informations_image['largeur'] - $informations_image['largeur'])/2;
221
				$debut_hauteur_a_copier = ($informations_image['largeur'] - $informations_image['largeur'])/2;
153
				$nb_pixels_largeur_a_copier = $informations_image['largeur'];
222
				$nb_pixels_largeur_a_copier = $informations_image['largeur'];
154
				$nb_pixels_hauteur_a_copier = $informations_image['largeur'];
223
				$nb_pixels_hauteur_a_copier = $informations_image['largeur'];
155
		}
224
		}
156
		
225
		
157
		$image_carre_temporaire = imagecreatetruecolor($cote_carre_non_redimensionne, $cote_carre_non_redimensionne);
226
		$image_carre_temporaire = imagecreatetruecolor($cote_carre_non_redimensionne, $cote_carre_non_redimensionne);
158
		
227
		
159
		imagecopyresampled($image_carre_temporaire, 
228
		imagecopyresampled($image_carre_temporaire, 
160
						$informations_image['image'], 
229
						$informations_image['image'], 
161
						0, 0, 
230
						0, 0, 
162
						$debut_largeur_a_copier,
231
						$debut_largeur_a_copier,
163
						$debut_hauteur_a_copier, 
232
						$debut_hauteur_a_copier, 
164
						$cote_carre_non_redimensionne, 
233
						$cote_carre_non_redimensionne, 
165
						$cote_carre_non_redimensionne, 
234
						$cote_carre_non_redimensionne, 
166
						$nb_pixels_largeur_a_copier, 
235
						$nb_pixels_largeur_a_copier, 
167
						$nb_pixels_hauteur_a_copier
236
						$nb_pixels_hauteur_a_copier
168
		);
237
		);
169
		
238
		
170
		$image_redimensionnee = imagecreatetruecolor($cote_carre, $cote_carre);
239
		$image_redimensionnee = imagecreatetruecolor($cote_carre, $cote_carre);
171
		
240
		
172
		imagecopyresampled($image_redimensionnee, 
241
		imagecopyresampled($image_redimensionnee, 
173
						$image_carre_temporaire, 
242
						$image_carre_temporaire, 
174
						0, 0, 
243
						0, 0, 
175
						0, 0, 
244
						0, 0, 
176
						$cote_carre, 
245
						$cote_carre, 
177
						$cote_carre, 
246
						$cote_carre, 
178
						$cote_carre_non_redimensionne, 
247
						$cote_carre_non_redimensionne, 
179
						$cote_carre_non_redimensionne
248
						$cote_carre_non_redimensionne
180
		);
249
		);
181
 
250
 
182
		return $image_redimensionnee;
251
		return $image_redimensionnee;
183
	}
252
	}
184
	
-
 
185
	
-
 
186
	/*public function extractionSelonDate() {
-
 
187
 
-
 
188
		$DB=$this->connectDB($this->config,'cel_db');
-
 
189
		
-
 
190
		$requete_selection_diff = 'SELECT * FROM cel_images WHERE ci_meta_date_ajout >= "2011-02-23"';
-
 
191
		
-
 
192
		$diff_image =& $DB->query($query_ordre);
-
 
193
		
-
 
194
		if (PEAR::isError($diff_imag))
-
 
195
		{
-
 
196
			$erreur = 'ERROR' ;
-
 
197
	        die($diff_image->getMessage());
-
 
198
	    }
-
 
199
		
-
 
200
		while ($row =& $diff_image->fetchrow(DB_FETCHMODE_ASSOC)) {
-
 
201
			
-
 
202
			$id = $row['ci_id_image'];
-
 
203
			
-
 
204
			$dossier = $this->obtenirDossierPourFormat($id,'L');
-
 
205
			$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'L');
-
 
206
			
-
 
207
			$chemin_complet = $dossier.'/'.$nom_fichier;
-
 
208
			
-
 
209
			
-
 
210
			
-
 
211
			$chemin_stockage_fichier = '/home/telabotap/www/sites/eflore/projets/cel_sauvegarde/'.str_replace(' ','_',$row['ci_nom_original']);
-
 
212
			copy($chemin_complet,$chemin_stockage_fichier);
-
 
213
			
-
 
214
		}
-
 
215
	}*/
-
 
216
	
253
	
217
	public function stockerFichierEtCreerMiniatures($fichier, $id) {
254
	public function stockerFichierEtCreerMiniatures($fichier, $id) {
218
		
255
		
219
		$chemin_base_fichier = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, 'O');	
256
		$chemin_base_fichier = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, 'O');	
220
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
257
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
221
	
258
	
222
		$chemin_fichier = $chemin_base_fichier.'/'.$nom_fichier;
259
		$chemin_fichier = $chemin_base_fichier.'/'.$nom_fichier;
223
		
260
		
-
 
261
		$deplacement_fichier = $this->stockerImageExterne($fichier['tmp_name'], $chemin_fichier);
-
 
262
		
224
		if(rename($fichier['tmp_name'],$chemin_fichier)) {
263
		if ($deplacement_fichier) {
225
 
264
 
226
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
265
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
227
			$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
266
			$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
228
			
267
			
229
			if($taux_compression < 100) {
268
			if ($taux_compression < 100 && $this->mode == self::MODE_IMAGEMAGICK) {
230
				$this->recompresserImageSurDisqueEnPreservantMeta($chemin_fichier, $taux_compression);
269
				$this->ecrireImageSurDisqueAvecMeta($chemin_fichier, $taux_compression);
231
			}
270
			}
232
				
271
				
233
			$infos_image_originale_stockee = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
272
			$infos_image_originale_stockee = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
234
			
273
			
235
			$formats = $this->getFormats();
274
			$formats = $this->getFormats();
236
			
275
			
237
			// creation de miniatures pour chacuns des formats définis
276
			// creation de miniatures pour chacuns des formats définis
238
			foreach($formats as $format) {
277
			foreach($formats as $format) {
239
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale_stockee, $format);
278
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale_stockee, $format);
240
			}
279
			}
241
	
280
	
242
	  		return true ;
281
	  		return true ;
243
	  		
282
	  		
244
		} else {
283
		} else {
245
			$erreur =  'ERROR : probleme durant le déplacement du fichier temporaire \n' ;
284
			$erreur =  'ERROR : probleme durant le déplacement du fichier temporaire \n' ;
246
			$this->logger('CEL_bugs',$erreur);
285
			$this->logger('CEL_bugs',$erreur);
247
  			return false ;
286
  			return false ;
248
		}
287
		}
249
	}
288
	}
-
 
289
	
-
 
290
	public function stockerImageExterne($chemin_fichier_temp, $chemin_destination) {
-
 
291
		
-
 
292
		if(is_uploaded_file($chemin_fichier_temp)) {
-
 
293
			$deplacement = move_uploaded_file($chemin_fichier_temp, $chemin_destination);
-
 
294
		} else {
-
 
295
			$deplacement = rename($chemin_fichier_temp, $chemin_destination);
-
 
296
		}
-
 
297
		
-
 
298
		return $deplacement;
-
 
299
	}
250
	
300
	
251
	public function creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, $format) {
301
	public function creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, $format) {
252
		
302
		
253
		$chemin_sur_serveur_final = $this->obtenirDossierPourFormat($id,$format);
303
		$chemin_sur_serveur_final = $this->obtenirDossierPourFormat($id,$format);
254
		
304
		
255
		if(!file_exists($chemin_sur_serveur_final))
305
		if (!file_exists($chemin_sur_serveur_final))
256
		{
306
		{
257
			if(mkdir($chemin_sur_serveur_final,$this->droits, true)) {
307
			if (mkdir($chemin_sur_serveur_final,$this->droits, true)) {
258
				chmod($chemin_sur_serveur_final,$this->droits);
308
				chmod($chemin_sur_serveur_final,$this->droits);
259
			}
309
			}
260
			else
310
			else
261
			{
311
			{
262
				$erreur =  'ERROR : probleme durant l\'écriture du dossier '.$format.' \n' ;
312
				$erreur =  'ERROR : probleme durant l\'écriture du dossier '.$format.' \n' ;
263
				echo $erreur;
313
				echo $erreur;
264
				$this->logger('CEL_bugs',$erreur);
314
				$this->logger('CEL_bugs',$erreur);
265
				return false;
315
				return false;
266
			}
316
			}
267
		}
317
		}
268
		
318
		
269
		return $chemin_sur_serveur_final;
319
		return $chemin_sur_serveur_final;
270
	}
320
	}
271
	
321
	
272
	public function obtenirDossierPourFormat($id, $format) {
322
	public function obtenirDossierPourFormat($id, $format) {
273
		
323
		
274
		$chemin_base = $this->config['cel_db']['chemin_images'];
324
		$chemin_base = $this->config['cel_db']['chemin_images'];
275
	
325
	
276
		$chemin_sur_serveur = $chemin_base ;
326
		$chemin_sur_serveur = $chemin_base ;
277
	
327
	
278
		$id = sprintf('%09s', $id) ;
328
		$id = sprintf('%09s', $id) ;
279
		$id = wordwrap($id, 3 , '_', true) ;
329
		$id = wordwrap($id, 3 , '_', true) ;
280
	
330
	
281
		$niveauDossier = split("_", $id) ;
331
		$niveauDossier = split("_", $id) ;
282
	
332
	
283
		$dossierNiveau1 = $niveauDossier[0] ;
333
		$dossierNiveau1 = $niveauDossier[0] ;
284
		$dossierNiveau2 = $niveauDossier[1] ;
334
		$dossierNiveau2 = $niveauDossier[1] ;
285
		
335
		
286
		$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
336
		$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2.'/'.$format;
287
		
337
		
288
		return $chemin_sur_serveur_final;
338
		return $chemin_sur_serveur_final;
289
	}
339
	}
290
	
340
	
291
	public function obtenirImageEtInfosPourChemin($chemin_fichier) {
341
	public function obtenirImageEtInfosPourChemin($chemin_fichier) {
292
		
342
		
293
		$image_et_infos = array();
343
		$image_et_infos = array();
294
		
344
		
295
		list($image_et_infos['largeur'], $image_et_infos['hauteur']) = getimagesize($chemin_fichier);		
345
		list($image_et_infos['largeur'], $image_et_infos['hauteur']) = getimagesize($chemin_fichier);		
296
		$image_et_infos['poids_octets'] = filesize($chemin_fichier);
346
		$image_et_infos['poids_octets'] = filesize($chemin_fichier);
297
		$image_et_infos['image'] = imagecreatefromjpeg($chemin_fichier);
347
		$image_et_infos['image'] = imagecreatefromjpeg($chemin_fichier);
-
 
348
		$image_et_infos['chemin'] = $chemin_fichier;
298
		
349
		
299
		return $image_et_infos;
350
		return $image_et_infos;
300
	}
351
	}
301
	
352
	
302
	public function obtenirDimensionsPourFormat($format) {
353
	public function obtenirDimensionsPourFormat($format) {
303
		
354
		
304
		$dimensions = array('largeur' => 0, 'hauteur' => 0);
355
		$dimensions = array('largeur' => 0, 'hauteur' => 0);
305
			
356
			
306
		if(isset($this->config['cel_db']['format_'.$format])) {
357
		if (isset($this->config['cel_db']['format_'.$format])) {
307
			
358
			
308
			$format_largeur_hauteur = split('_', $this->config['cel_db']['format_'.$format]);
359
			$format_largeur_hauteur = split('_', $this->config['cel_db']['format_'.$format]);
309
			
360
			
310
			$dimensions['largeur'] = $format_largeur_hauteur[0];
361
			$dimensions['largeur'] = $format_largeur_hauteur[0];
311
			$dimensions['hauteur'] = $format_largeur_hauteur[1];
362
			$dimensions['hauteur'] = $format_largeur_hauteur[1];
312
		}
363
		}
313
		
364
		
314
		return $dimensions;
365
		return $dimensions;
315
		
366
		
316
	}
367
	}
317
	
368
	
318
	public function calculerTailleImage($informations_images, $taille_max) {
369
	public function calculerTailleImage($informations_images, $taille_max) {
319
	
370
	
320
	        $HL_redimension = array();
371
	        $HL_redimension = array();
321
	        
372
	        
322
	        if($this->estPaysage($informations_images)) {
373
	        if ($this->estPaysage($informations_images)) {
323
	        
374
	        
324
		        $rapport = $informations_images['hauteur']/$informations_images['largeur'] ;
375
		        $rapport = $informations_images['hauteur']/$informations_images['largeur'] ;
325
		        $HL_redimension['largeur'] = round($taille_max) ;
376
		        $HL_redimension['largeur'] = round($taille_max) ;
326
		        $HL_redimension['hauteur'] = round($taille_max*$rapport) ;
377
		        $HL_redimension['hauteur'] = round($taille_max*$rapport) ;
327
		        
378
		        
328
	        } else {
379
	        } else {
329
	        	$rapport = $informations_images['largeur']/$informations_images['hauteur'] ;
380
	        	$rapport = $informations_images['largeur']/$informations_images['hauteur'] ;
330
		        $HL_redimension['hauteur'] = round($taille_max) ;
381
		        $HL_redimension['hauteur'] = round($taille_max) ;
331
		        $HL_redimension['largeur'] = round($taille_max*$rapport) ;
382
		        $HL_redimension['largeur'] = round($taille_max*$rapport) ;
332
	        }
383
	        }
333
	        
384
	        
334
	        return $HL_redimension;
385
	        return $HL_redimension;
335
	}
386
	}
336
	
387
	
337
	public function getFormats() {
388
	public function getFormats() {
338
		return $this->formats;
389
		return $this->formats;
339
	}
390
	}
340
	
391
	
341
	public function estUnFormatCarre($format) {
392
	public function estUnFormatCarre($format) {
342
		
393
		
343
		return (strpos($format,'C') === 0);		
394
		return (strpos($format,'C') === 0);		
344
	}
395
	}
345
	
396
	
346
	public function estUnFormatRogne($format) {
397
	public function estUnFormatRogne($format) {
347
 
398
 
348
		return (strpos($format,'R') === 1);		
399
		return (strpos($format,'R') === 1);		
349
	}
400
	}
350
	
401
	
351
	public function estPaysage($informations_images) {
402
	public function estPaysage($informations_images) {
352
		return $informations_images['largeur'] > $informations_images['hauteur'];
403
		return $informations_images['largeur'] > $informations_images['hauteur'];
353
	}
404
	}
354
	
405
	
355
	public function estPortait($informations_images) {
406
	public function estPortait($informations_images) {
356
		return $informations_images['largeur'] < $informations_images['hauteur'];
407
		return $informations_images['largeur'] < $informations_images['hauteur'];
357
	}
408
	}
358
	
409
	
359
	public function renvoyerTauxCompressionPourPoids($poids_octets) {
410
	public function renvoyerTauxCompressionPourPoids($poids_octets) {
360
 
411
 
361
		$poids_max_octets = $this->config['cel_db']['taille_max'];
412
		$poids_max_octets = $this->config['cel_db']['taille_max'];
362
		
413
		
363
		$ratio_compression = 100 ;
414
		$ratio_compression = 100 ;
364
		
415
		
365
	    if($poids_octets >= $poids_max_octets) {
416
	    if ($poids_octets >= $poids_max_octets) {
366
	      $ratio_compression = 75 ;
417
	      $ratio_compression = 75 ;
367
	    }
418
	    }
368
	    
419
	    
369
	    return $ratio_compression;
420
	    return $ratio_compression;
370
	}
421
	}
371
	
422
	
372
	public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
423
	public function convertirIdBddVersNomFichier($id, $format, $extension = 'jpg') {
373
		
424
		
374
			// creation du format original
425
			// creation du format original
375
		$id_avec_zeros = sprintf('%09s', $id) ;
426
		$id_avec_zeros = sprintf('%09s', $id) ;
376
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
427
		$id_avec_zeros_underscores = wordwrap($id_avec_zeros, 3 , '_', true) ;
377
		
428
		
378
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
429
		$nom_fichier = $id_avec_zeros_underscores.'_'.$format.'.'.$extension;
379
		
430
		
380
		return $nom_fichier;
431
		return $nom_fichier;
381
	}
432
	}
382
	
433
	
383
	public function convertirBaseNomFichierVersIdBdd($nom_fichier, $formats) {
434
	public function convertirBaseNomFichierVersIdBdd($nom_fichier, $formats) {
384
		
435
		
385
		$nom_fichier_sans_extension = trim($nom_fichier, '.jpg');
436
		$nom_fichier_sans_extension = trim($nom_fichier, '.jpg');
386
		
437
		
387
		foreach($formats as $format) {
438
		foreach($formats as $format) {
388
			$nom_fichier_sans_extension = trim($nom_fichier_sans_extension, '_'.$format);
439
			$nom_fichier_sans_extension = trim($nom_fichier_sans_extension, '_'.$format);
389
		}
440
		}
390
		
441
		
391
		$id_image = str_replace('_', '', $nom_fichier_sans_extension);
442
		$id_image = str_replace('_', '', $nom_fichier_sans_extension);
392
			
443
			
393
		// suppression des 0 devant
444
		// suppression des 0 devant
394
		$id_image += 0;
445
		$id_image += 0;
395
		
446
		
396
		return $id_image;
447
		return $id_image;
397
	}
448
	}
398
	
449
	
399
	public function ecrireImageSurDisque($image, $id, $format, $compression = 100) {
450
	public function ecrireImageSurDisque($image_binaire, $id, $format, $compression = 100) {
400
		
451
		
401
		umask(0);
452
		umask(0);
402
		
453
		
403
		$chemin_sur_serveur_final = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, $format);
454
		$chemin_sur_serveur_final = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, $format);
404
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
455
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
405
		
456
		
406
		if(file_exists($chemin_sur_serveur_final.'/'.$nom_fichier)) {
457
		if (file_exists($chemin_sur_serveur_final.'/'.$nom_fichier)) {
407
			unlink($chemin_sur_serveur_final.'/'.$nom_fichier);
458
			unlink($chemin_sur_serveur_final.'/'.$nom_fichier);
408
		}
459
		}
409
		
460
		
410
		// attention ceci ne preserve pas les metadonnées
461
		// attention ceci ne preserve pas les metadonnées
411
		imagejpeg($image,$chemin_sur_serveur_final.'/'.$nom_fichier, $compression);
462
		imagejpeg($image_binaire, $chemin_sur_serveur_final.'/'.$nom_fichier, $compression);
412
		chmod($chemin_sur_serveur_final.'/'.$nom_fichier,$this->droits);
463
		chmod($chemin_sur_serveur_final.'/'.$nom_fichier,$this->droits);
413
	}
464
	}
414
	
-
 
415
	
465
		
416
	public function recompresserImageSurDisqueEnPreservantMeta($chemin_fichier, $compression = 100) {
466
	public function ecrireImageSurDisqueAvecMeta($image_a_stocker, $compression = 100) {
-
 
467
 
417
 
468
		$image_a_stocker = new Imagick();
418
		/*$blob = file_get_contents($chemin_fichier);
469
		$image_a_stocker->readImageBlob($image_a_stocker);
419
			
-
 
420
		$image_a_compresser = new Imagick();
470
	
421
		$image_a_compresser->readImageBlob($blob, $chemin_fichier);
471
		// l'utilisation d'image magick préserve les métadonnées lors d'une recompression
422
		$image_a_compresser->setformat("jpeg");
472
		$image_a_stocker->setformat("jpeg");
423
		$image_a_compresser->setImageCompression(imagick::COMPRESSION_JPEG); 
473
		$image_a_stocker->setImageCompression(imagick::COMPRESSION_JPEG); 
424
		$image_a_compresser->setCompressionQuality($compression);
474
		$image_a_stocker->setCompressionQuality($compression);
425
		$image_a_compresser->writeImage($chemin_fichier);
475
		$image_a_stocker->writeImage($chemin_fichier);
426
		$image_a_compresser->destroy();	
476
		$image_a_stocker->destroy();	
427
		
477
		
428
		chmod($chemin_sur_serveur_final.'/'.$nom_fichier,$this->droits);*/
478
		chmod($chemin_sur_serveur_final.'/'.$nom_fichier,$this->droits);
429
	}
479
	}
430
	
480
	
431
	public function renvoyerEtCreerImageCarreeBlancheSelonFormat($cote) {
481
	public function renvoyerEtCreerImageCarreeBlancheSelonFormat($cote) {
432
		
482
		
433
		$image_blanche = imagecreatetruecolor($cote, $cote);		
483
		$image_blanche = imagecreatetruecolor($cote, $cote);		
434
		$blanc = imagecolorallocate($image_blanche, 255, 255, 255);
484
		$blanc = imagecolorallocate($image_blanche, 255, 255, 255);
435
		imagefilledrectangle($image_blanche, 0, 0, $cote, $cote, $blanc);
485
		imagefilledrectangle($image_blanche, 0, 0, $cote, $cote, $blanc);
436
		
486
		
437
		return $image_blanche;
487
		return $image_blanche;
438
	}
488
	}
439
	
489
	
440
	public function detruireImageEnMemoire($image) {		
490
	public function detruireImageEnMemoire($image) {		
441
		imagedestroy($image);
491
		imagedestroy($image);
442
	}
492
	}
443
	
493
	
444
	public function detruireImageSurDisque($id) {
494
	public function detruireImageSurDisque($id) {
445
		
495
		
446
		$formats = $this->getFormats();
496
		$formats = $this->getFormats();
447
		
497
		
448
		// on detruit aussi l'image originale
498
		// on detruit aussi l'image originale
449
		$formats[] = 'O';
499
		$formats[] = 'O';
450
		
500
		
451
		$destruction_formats_fichier = false;
501
		$destruction_formats_fichier = false;
452
		
502
		
453
		// destructions de chacuns des formats définis
503
		// destructions de chacuns des formats définis
454
		foreach($formats as $format) {
504
		foreach($formats as $format) {
455
			
505
			
456
			$dossier_format = $this->obtenirDossierPourFormat($id, $format);
506
			$dossier_format = $this->obtenirDossierPourFormat($id, $format);
457
			$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
507
			$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
458
			
508
			
459
			if(file_exists($dossier_format.'/'.$nom_fichier)) {
509
			if (file_exists($dossier_format.'/'.$nom_fichier)) {
460
				$destruction_formats_fichier = unlink($dossier_format.'/'.$nom_fichier);
510
				$destruction_formats_fichier = unlink($dossier_format.'/'.$nom_fichier);
461
			} else {
511
			} else {
462
				$destruction_formats_fichier = true;
512
				$destruction_formats_fichier = true;
463
			}
513
			}
464
		}
514
		}
465
		
515
		
466
		return $destruction_formats_fichier;
516
		return $destruction_formats_fichier;
467
	}
517
	}
-
 
518
	
-
 
519
	/* 
-
 
520
	 * edge-maximizing crop
-
 
521
	 * determines center-of-edginess, then tries different-sized crops around it. 
-
 
522
	 * picks the crop with the highest normalized edginess.
-
 
523
	 * see documentation on how to tune the algorithm
-
 
524
	 *
-
 
525
	 * $informations_image - le tableau d'informations sur l'image tel que renvoyé par la fonction obtenirImageEtInfosPourChemin
-
 
526
	 * $format - le format (ex. : CS, XS, XL, CRS)
-
 
527
	*/
-
 
528
	function opticrop($informations_image, $format) {
-
 
529
 
-
 
530
		umask(0);
-
 
531
		
-
 
532
		$nom_temp = md5(time());
-
 
533
		$out = '/home/aurelien/web/file_tmp/'.$nom_temp;
-
 
534
		
-
 
535
		$dimension_vignettes = $this->obtenirDimensionsPourFormat($format);
-
 
536
		
-
 
537
		$largeur_vignette = $dimension_vignettes['largeur'];
-
 
538
		$hauteur_vignette = $dimension_vignettes['hauteur'];
-
 
539
		
-
 
540
	    // source dimensions
-
 
541
	    $largeur_image_originale = $informations_image['largeur'];
-
 
542
	    $hauteur_image_originale = $informations_image['hauteur'];
-
 
543
	    
-
 
544
	    $chemin_image = $informations_image['chemin'];
-
 
545
	    
-
 
546
	    //if ($largeur_vignette > $largeur_image_originale || $hauteur_vignette > $hauteur_image_originale)
-
 
547
	    //    die("Target dimensions must be smaller or equal to source dimensions.");
-
 
548
	
-
 
549
	    // parameters for the edge-maximizing crop algorithm
-
 
550
	    $r = 1;         // radius of edge filter
-
 
551
	    $nk = 9;        // scale count: number of crop sizes to try
-
 
552
	    $gamma = 0.2;   // edge normalization parameter -- see documentation
-
 
553
	    $ar = $largeur_vignette/$hauteur_vignette;    // target aspect ratio (AR)
-
 
554
	    $ar0 = $largeur_image_originale/$hauteur_image_originale;    // original aspect ratio (AR)
-
 
555
	
-
 
556
	    //echo("$chemin_image: $largeur_image_originale x $hauteur_image_originale => $largeur_vignette x $hauteur_vignette");
-
 
557
	    $img = new Imagick($chemin_image);
-
 
558
	    $imgcp = clone $img;
-
 
559
	
-
 
560
	    // compute center of edginess
-
 
561
	    $img->edgeImage($r);
-
 
562
	    $img->modulateImage(100,0,100); // grayscale
-
 
563
	    $img->blackThresholdImage("#0f0f0f");
-
 
564
	    $img->writeImage($out);
-
 
565
	    // use gd for random pixel access
-
 
566
	    $im = ImageCreateFromJpeg($out);
-
 
567
	    $xcenter = 0;
-
 
568
	    $ycenter = 0;
-
 
569
	    $sum = 0;
-
 
570
	    $n = 100000;
-
 
571
	    for ($k=0; $k<$n; $k++) {
-
 
572
	        $i = mt_rand(0,$largeur_image_originale-1);
-
 
573
	        $j = mt_rand(0,$hauteur_image_originale-1);
-
 
574
	        $val = imagecolorat($im, $i, $j) & 0xFF;
-
 
575
	        $sum += $val;
-
 
576
	        $xcenter += ($i+1)*$val;
-
 
577
	        $ycenter += ($j+1)*$val;
-
 
578
	    }
-
 
579
	    $xcenter /= $sum;
-
 
580
	    $ycenter /= $sum;
-
 
581
	
-
 
582
	    // crop source img to target AR
-
 
583
	    if ($largeur_image_originale/$hauteur_image_originale > $ar) {
-
 
584
	        // source AR wider than target
-
 
585
	        // crop width to target AR
-
 
586
	        $wcrop0 = round($ar*$hauteur_image_originale);
-
 
587
	        $hcrop0 = $hauteur_image_originale;
-
 
588
	    } 
-
 
589
	    else {
-
 
590
	        // crop height to target AR
-
 
591
	        $wcrop0 = $largeur_image_originale;
-
 
592
	        $hcrop0 = round($largeur_image_originale/$ar);
-
 
593
	    }
-
 
594
	
-
 
595
	    // crop parameters for all scales and translations
-
 
596
	    $params = array();
-
 
597
	
-
 
598
	    // crop at different scales
-
 
599
	    $hgap = $hcrop0 - $hauteur_vignette;
-
 
600
	    $hinc = ($nk == 1) ? 0 : $hgap / ($nk - 1);
-
 
601
	    $wgap = $wcrop0 - $largeur_vignette;
-
 
602
	    $winc = ($nk == 1) ? 0 : $wgap / ($nk - 1);
-
 
603
	
-
 
604
	    // find window with highest normalized edginess
-
 
605
	    $n = 10000;
-
 
606
	    $maxbetanorm = 0;
-
 
607
	    $maxfile = '';
-
 
608
	    $maxparam = array('w'=>0, 'h'=>0, 'x'=>0, 'y'=>0);
-
 
609
	    
-
 
610
	    for ($k = 0; $k < $nk; $k++) {
-
 
611
	        $hcrop = round($hcrop0 - $k*$hinc);
-
 
612
	        $wcrop = round($wcrop0 - $k*$winc);
-
 
613
	        $xcrop = $xcenter - $wcrop / 2;
-
 
614
	        $ycrop = $ycenter - $hcrop / 2;
-
 
615
	        //echo("crop: $wcrop, $hcrop, $xcrop, $ycrop");
-
 
616
	
-
 
617
	        if ($xcrop < 0) $xcrop = 0;
-
 
618
	        if ($xcrop+$wcrop > $largeur_image_originale) $xcrop = $largeur_image_originale-$wcrop;
-
 
619
	        if ($ycrop < 0) $ycrop = 0;
-
 
620
	        if ($ycrop+$hcrop > $hauteur_image_originale) $ycrop = $hauteur_image_originale-$hcrop;
-
 
621
		        
-
 
622
	        /*if (self::MODE_DEBUG) {
-
 
623
	        	// debug
-
 
624
	        	$currfile = '/home/aurelien/web/file_tmp/'."image$k.jpg";
-
 
625
	        	
-
 
626
	            $currimg = clone $img;
-
 
627
	            $c= new ImagickDraw(); 
-
 
628
	            $c->setFillColor("red"); 
-
 
629
	            $c->circle($xcenter, $ycenter, $xcenter, $ycenter+4); 
-
 
630
	            $currimg->drawImage($c); 
-
 
631
	            $currimg->cropImage($wcrop, $hcrop, $xcrop, $ycrop);
-
 
632
	            $currimg->writeImage($currfile);
-
 
633
	            $currimg->destroy();
-
 
634
	        }*/
-
 
635
	
-
 
636
	        $beta = 0;
-
 
637
	        for ($c=0; $c<$n; $c++) {
-
 
638
	            $i = mt_rand(0,$wcrop-1);
-
 
639
	            $j = mt_rand(0,$hcrop-1);
-
 
640
	            $beta += imagecolorat($im, $xcrop+$i, $ycrop+$j) & 0xFF;
-
 
641
	        }
-
 
642
	        $area = $wcrop * $hcrop;
-
 
643
	        $betanorm = $beta / ($n*pow($area, $gamma-1));
-
 
644
	        // echo("beta: $beta; betan: $betanorm");
-
 
645
	        // echo("image$k.jpg:<br/>\n<img src=\"$currfile\"/>");
-
 
646
	        // best image found, save it
-
 
647
	        
-
 
648
	        if ($betanorm > $maxbetanorm) {
-
 
649
	        	
-
 
650
	            $maxbetanorm = $betanorm;
-
 
651
	            $maxparam['w'] = $wcrop;
-
 
652
	            $maxparam['h'] = $hcrop;
-
 
653
	            $maxparam['x'] = $xcrop;
-
 
654
	            $maxparam['y'] = $ycrop;
-
 
655
	            // $maxfile = $currfile;
-
 
656
	        }
-
 
657
	    }
-
 
658
	
-
 
659
        // return image
-
 
660
        $imgcp->cropImage($maxparam['w'], $maxparam['h'], $maxparam['x'], $maxparam['y']);
-
 
661
        $imgcp->scaleImage($largeur_vignette, $hauteur_vignette);
-
 
662
        $imgcp->writeImage($out);
-
 
663
	    chmod($out, 0777);
-
 
664
	    $img->destroy();
-
 
665
	    $imgcp->destroy();
-
 
666
	    
-
 
667
	    $image_sortie = ImageCreateFromJpeg($out);
-
 
668
	    unlink($out);
-
 
669
	    
-
 
670
	    return $image_sortie;
-
 
671
	}
-
 
672
	
468
}
673
}
469
?>
674
?>