Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1883 Rev 2083
Line 84... Line 84...
84
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
84
					$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
85
				}
85
				}
86
		    }
86
		    }
87
		}
87
		}
88
	}
88
	}
-
 
89
	
-
 
90
	public function creerOuRenvoyerImage($id, $format) {
-
 
91
		$dossier = $this->obtenirDossierPourFormat($id, $format);
-
 
92
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, $format);
-
 
93
		$chemin_image = $dossier.'/'.$nom_fichier;	
-
 
94
 
-
 
95
		$image = false;
-
 
96
		if(!file_exists($chemin_image)) {
-
 
97
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($this->obtenirCheminImageOriginale($id));
-
 
98
			if($infos_image_originale) {
-
 
99
				$debut = microtime();
-
 
100
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale, $format);
-
 
101
				
-
 
102
				$image = file_get_contents($chemin_image);
-
 
103
			}
-
 
104
		} else {
-
 
105
			$image = file_get_contents($chemin_image);
-
 
106
		}
-
 
107
		
-
 
108
		return $image;
-
 
109
	}
Line 89... Line 110...
89
 
110
 
90
	public function creerMiniatureImageSelonFormat($infos_image_originale, $format = 'O') {
111
	public function creerMiniatureImageSelonFormat($infos_image_originale, $format = 'O') {
91
		if ($format == 'O') {
112
		if ($format == 'O') {
92
			// format original : rien à faire
113
			// format original : rien à faire
Line 112... Line 133...
112
			}
133
			}
113
		}
134
		}
Line 114... Line 135...
114
 
135
 
115
		return $image_redimensionnee;
136
		return $image_redimensionnee;
-
 
137
	}
-
 
138
	
-
 
139
	public function stockerFichierOriginal($fichier, $id) {
-
 
140
		$chemin_fichier_origine = is_array($fichier) ? $fichier['tmp_name'] : $fichier;
-
 
141
		
-
 
142
		$chemin_base_fichier = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, 'O');
-
 
143
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
-
 
144
		
-
 
145
		$chemin_fichier = $chemin_base_fichier.'/'.$nom_fichier;
-
 
146
		
-
 
147
		$deplacement_fichier = $this->stockerImageExterne($chemin_fichier_origine, $chemin_fichier);
-
 
148
		
-
 
149
		if ($deplacement_fichier) {
-
 
150
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
-
 
151
			$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
-
 
152
		
-
 
153
			if ($taux_compression < 100 && $this->mode == self::MODE_IMAGEMAGICK) {
-
 
154
				$this->ecrireImageSurDisqueAvecMeta($chemin_fichier, $taux_compression);
-
 
155
			}
-
 
156
 
-
 
157
			return $infos_image_originale;
-
 
158
		
-
 
159
		} else {
-
 
160
			$erreur =  'ERROR : probleme durant le déplacement du fichier temporaire \n' ;
-
 
161
			$this->logger('CEL_bugs',$erreur);
-
 
162
			return false ;
-
 
163
		}
-
 
164
	}
-
 
165
	
-
 
166
	public function stockerFichierEtCreerMiniatures($fichier, $id) {
-
 
167
		
-
 
168
		$infos_image_originale_stockee = $this->stockerFichierOriginal($fichier, $id);
-
 
169
		if($infos_image_originale_stockee) {
-
 
170
			$formats = $this->getFormats();
-
 
171
	
-
 
172
			// creation de miniatures pour chacuns des formats définis
-
 
173
			foreach($formats as $format) {
-
 
174
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale_stockee, $format);
-
 
175
			}
-
 
176
		} else {
-
 
177
			$erreur =  'ERROR : impossible d\'obtenir les informations sur l\'image originale \n' ;
-
 
178
			$this->logger('CEL_bugs',$erreur);
-
 
179
			return false ;
-
 
180
		}
-
 
181
	
-
 
182
		return true ;
Line 116... Line 183...
116
	}
183
	}
117
 
184
 
Line 118... Line 185...
118
	public function creerEtStockerMiniatureFichierImageSelonFormat($id ,$infos_image_originale, $format = 'O') {
185
	public function creerEtStockerMiniatureFichierImageSelonFormat($id ,$infos_image_originale, $format = 'O') {
Line 229... Line 296...
229
		);
296
		);
Line 230... Line 297...
230
 
297
 
231
		return $image_redimensionnee;
298
		return $image_redimensionnee;
Line 232... Line -...
232
	}
-
 
233
 
-
 
234
	public function stockerFichierEtCreerMiniatures($fichier, $id) {
-
 
235
		$chemin_fichier_origine = is_array($fichier) ? $fichier['tmp_name'] : $fichier;
-
 
236
		
-
 
237
		$chemin_base_fichier = $this->creerSiNecessaireEtRenvoyerCheminStockageFichierPourIdEtFormat($id, 'O');
-
 
238
		$nom_fichier = $this->convertirIdBddVersNomFichier($id, 'O');
-
 
239
 
-
 
240
		$chemin_fichier = $chemin_base_fichier.'/'.$nom_fichier;
-
 
241
 
-
 
242
		$deplacement_fichier = $this->stockerImageExterne($chemin_fichier_origine, $chemin_fichier);
-
 
243
 
-
 
244
		if ($deplacement_fichier) {
-
 
245
 
-
 
246
			$infos_image_originale = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
-
 
247
			$taux_compression = $this->renvoyerTauxCompressionPourPoids($infos_image_originale['poids_octets']);
-
 
248
 
-
 
249
			if ($taux_compression < 100 && $this->mode == self::MODE_IMAGEMAGICK) {
-
 
250
				$this->ecrireImageSurDisqueAvecMeta($chemin_fichier, $taux_compression);
-
 
251
			}
-
 
252
 
-
 
253
			$infos_image_originale_stockee = $this->obtenirImageEtInfosPourChemin($chemin_fichier);
-
 
254
 
-
 
255
			$formats = $this->getFormats();
-
 
256
 
-
 
257
			// creation de miniatures pour chacuns des formats définis
-
 
258
			foreach($formats as $format) {
-
 
259
				$this->creerEtStockerMiniatureFichierImageSelonFormat($id, $infos_image_originale_stockee, $format);
-
 
260
			}
-
 
261
 
-
 
262
	  		return true ;
-
 
263
 
-
 
264
		} else {
-
 
265
			$erreur =  'ERROR : probleme durant le déplacement du fichier temporaire \n' ;
-
 
266
			$this->logger('CEL_bugs',$erreur);
-
 
267
  			return false ;
-
 
268
		}
-
 
269
	}
299
	}
270
 
300
 
271
	public function stockerImageExterne($chemin_fichier_temp, $chemin_destination) {
301
	public function stockerImageExterne($chemin_fichier_temp, $chemin_destination) {
272
		if (is_uploaded_file($chemin_fichier_temp)) {
302
		if (is_uploaded_file($chemin_fichier_temp)) {
273
			$deplacement = move_uploaded_file($chemin_fichier_temp, $chemin_destination);
303
			$deplacement = move_uploaded_file($chemin_fichier_temp, $chemin_destination);