Completed
Push — master ( 14e8ce...7e60d3 )
by cam
04:26
created
ecrire/inc/filtres_images_lib_mini.php 2 patches
Doc Comments   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
  *
88 88
  * @param bool|string $stat
89 89
  *     true, false ou le statut déjà défini si traitements enchaînés.
90
- * @return bool
90
+ * @return false|null
91 91
  *     true si il faut supprimer le fichier temporaire ; false sinon.
92 92
  */
93 93
 function statut_effacer_images_temporaires($stat) {
@@ -370,8 +370,7 @@  discard block
 block discarded – undo
370 370
 
371 371
 
372 372
 /**
373
- * @param string $quoi
374
- * @return array
373
+ * @return string[]
375 374
  */
376 375
 function _image_extensions_acceptees_en_entree() {
377 376
 	static $extensions = null;
@@ -409,6 +408,9 @@  discard block
 block discarded – undo
409 408
 	return $extensions;
410 409
 }
411 410
 
411
+/**
412
+ * @param string $extension
413
+ */
412 414
 function _image_extension_normalisee($extension){
413 415
 	$extension = strtolower($extension);
414 416
 	if ($extension === 'jpeg') {
@@ -1450,7 +1452,7 @@  discard block
 block discarded – undo
1450 1452
  * @param int $srcHeight Hauteur de l'image source
1451 1453
  * @param int $maxWidth Largeur maximum souhaitée
1452 1454
  * @param int $maxHeight Hauteur maximum souhaitée
1453
- * @return array Liste [ largeur, hauteur, ratio de réduction ]
1455
+ * @return integer[] Liste [ largeur, hauteur, ratio de réduction ]
1454 1456
  **/
1455 1457
 function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1456 1458
 	$ratioWidth = $srcWidth / $maxWidth;
@@ -1488,7 +1490,7 @@  discard block
 block discarded – undo
1488 1490
  * @param int $srcHeight Hauteur de l'image source
1489 1491
  * @param int $maxWidth Largeur maximum souhaitée
1490 1492
  * @param int $maxHeight Hauteur maximum souhaitée
1491
- * @return array Liste [ largeur, hauteur, ratio de réduction ]
1493
+ * @return integer[] Liste [ largeur, hauteur, ratio de réduction ]
1492 1494
  **/
1493 1495
 function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1494 1496
 	$ratioWidth = $srcWidth / $maxWidth;
@@ -1707,7 +1709,7 @@  discard block
 block discarded – undo
1707 1709
 	/**
1708 1710
 	 * Transforme une ressource GD en image au format ICO
1709 1711
 	 *
1710
-	 * @param array $gd_image_array
1712
+	 * @param resource[] $gd_image_array
1711 1713
 	 *     Tableau de ressources d'images GD
1712 1714
 	 * @return string
1713 1715
 	 *     Image au format ICO
Please login to merge, or discard this patch.
Indentation   +1218 added lines, -1218 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 include_spip('inc/filtres'); // par precaution
25 25
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -39,21 +39,21 @@  discard block
 block discarded – undo
39 39
  *     Le code de la couleur en hexadécimal.
40 40
  */
41 41
 function _couleur_dec_to_hex($red, $green, $blue) {
42
-	$red = dechex($red);
43
-	$green = dechex($green);
44
-	$blue = dechex($blue);
45
-
46
-	if (strlen($red) == 1) {
47
-		$red = "0" . $red;
48
-	}
49
-	if (strlen($green) == 1) {
50
-		$green = "0" . $green;
51
-	}
52
-	if (strlen($blue) == 1) {
53
-		$blue = "0" . $blue;
54
-	}
55
-
56
-	return "$red$green$blue";
42
+    $red = dechex($red);
43
+    $green = dechex($green);
44
+    $blue = dechex($blue);
45
+
46
+    if (strlen($red) == 1) {
47
+        $red = "0" . $red;
48
+    }
49
+    if (strlen($green) == 1) {
50
+        $green = "0" . $green;
51
+    }
52
+    if (strlen($blue) == 1) {
53
+        $blue = "0" . $blue;
54
+    }
55
+
56
+    return "$red$green$blue";
57 57
 }
58 58
 
59 59
 /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
  *     Un tableau des 3 éléments : rouge, vert, bleu.
66 66
  */
67 67
 function _couleur_hex_to_dec($couleur) {
68
-	$couleur = couleur_html_to_hex($couleur);
69
-	$couleur = ltrim($couleur, '#');
70
-	if (strlen($couleur) === 3) {
71
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
-	}
73
-	$retour["red"] = hexdec(substr($couleur, 0, 2));
74
-	$retour["green"] = hexdec(substr($couleur, 2, 2));
75
-	$retour["blue"] = hexdec(substr($couleur, 4, 2));
76
-
77
-	return $retour;
68
+    $couleur = couleur_html_to_hex($couleur);
69
+    $couleur = ltrim($couleur, '#');
70
+    if (strlen($couleur) === 3) {
71
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
+    }
73
+    $retour["red"] = hexdec(substr($couleur, 0, 2));
74
+    $retour["green"] = hexdec(substr($couleur, 2, 2));
75
+    $retour["blue"] = hexdec(substr($couleur, 4, 2));
76
+
77
+    return $retour;
78 78
 }
79 79
 
80 80
 /**
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
  *     true si il faut supprimer le fichier temporaire ; false sinon.
92 92
  */
93 93
 function statut_effacer_images_temporaires($stat) {
94
-	static $statut = false; // par defaut on grave toute les images
95
-	if ($stat === 'get') {
96
-		return $statut;
97
-	}
98
-	$statut = $stat ? true : false;
94
+    static $statut = false; // par defaut on grave toute les images
95
+    if ($stat === 'get') {
96
+        return $statut;
97
+    }
98
+    $statut = $stat ? true : false;
99 99
 }
100 100
 
101 101
 
@@ -148,224 +148,224 @@  discard block
 block discarded – undo
148 148
  *     - array : tableau décrivant de l'image
149 149
  */
150 150
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
151
-	static $images_recalcul = array();
152
-	if (strlen($img) == 0) {
153
-		return false;
154
-	}
155
-
156
-	$source = trim(extraire_attribut($img, 'src'));
157
-	if (strlen($source) < 1) {
158
-		$source = $img;
159
-		$img = "<img src='$source' />";
160
-	} # gerer img src="data:....base64"
161
-	elseif (preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
162
-	  and $extension = _image_trouver_extension_depuis_mime("image/".$regs[1])
163
-		and in_array($extension, _image_extensions_acceptees_en_entree())
164
-	) {
165
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
166
-		if (!file_exists($local)) {
167
-			ecrire_fichier($local, base64_decode($regs[2]));
168
-		}
169
-		$source = $local;
170
-		$img = inserer_attribut($img, 'src', $source);
171
-		# eviter les mauvaises surprises lors de conversions de format
172
-		$img = inserer_attribut($img, 'width', '');
173
-		$img = inserer_attribut($img, 'height', '');
174
-	}
175
-
176
-	// les protocoles web prennent au moins 3 lettres
177
-	if (tester_url_absolue($source)) {
178
-		include_spip('inc/distant');
179
-		$fichier = _DIR_RACINE . copie_locale($source);
180
-		if (!$fichier) {
181
-			return "";
182
-		}
183
-	} else {
184
-		// enlever le timestamp eventuel
185
-		if (strpos($source, "?") !== false) {
186
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
187
-		}
188
-		if (strpos($source, "?") !== false
189
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
190
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
191
-		) {
192
-			$source = $f;
193
-		}
194
-		$fichier = $source;
195
-	}
196
-
197
-	$terminaison_dest = "";
198
-	if ($terminaison = _image_trouver_extension($fichier)) {
199
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
200
-	}
201
-
202
-	if ($forcer_format !== false
203
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
204
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,_image_extensions_acceptees_en_sortie()))) {
205
-		$terminaison_dest = $forcer_format;
206
-	}
207
-
208
-	if (!$terminaison_dest) {
209
-		return false;
210
-	}
211
-
212
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
213
-	$fichier_dest = $nom_fichier;
214
-	if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
215
-		or @file_exists($f = $fichier)
216
-	) {
217
-		// on passe la balise img a taille image qui exraira les attributs si possible
218
-		// au lieu de faire un acces disque sur le fichier
219
-		list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
220
-		$date_src = @filemtime($f);
221
-	} elseif (@file_exists($f = "$fichier.src")
222
-		and lire_fichier($f, $valeurs)
223
-		and $valeurs = unserialize($valeurs)
224
-		and isset($valeurs["hauteur_dest"])
225
-		and isset($valeurs["largeur_dest"])
226
-	) {
227
-		$ret["hauteur"] = $valeurs["hauteur_dest"];
228
-		$ret["largeur"] = $valeurs["largeur_dest"];
229
-		$date_src = $valeurs["date"];
230
-	} // pas de fichier source par la
231
-	else {
232
-		return false;
233
-	}
234
-
235
-	// pas de taille mesurable
236
-	if (!($ret["hauteur"] or $ret["largeur"])) {
237
-		return false;
238
-	}
239
-
240
-	// les images calculees dependent du chemin du fichier source
241
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
242
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
243
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
244
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
245
-	// alors que ca concerne peu de site au final
246
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
247
-	$identifiant = $fichier;
248
-
249
-	// cas general :
250
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
251
-	// cas particulier de reduire :
252
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
253
-	$cache = "cache-gd2";
254
-	if (substr($effet, 0, 7) == 'reduire') {
255
-		list(, $maxWidth, $maxHeight) = explode('-', $effet);
256
-		list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
257
-		$ret['largeur_dest'] = $destWidth;
258
-		$ret['hauteur_dest'] = $destHeight;
259
-		$effet = "L{$destWidth}xH$destHeight";
260
-		$cache = "cache-vignettes";
261
-		$fichier_dest = basename($fichier_dest);
262
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
263
-			// on garde la terminaison initiale car image simplement copiee
264
-			// et on postfixe son nom avec un md5 du path
265
-			$terminaison_dest = $terminaison;
266
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
267
-		} else {
268
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
269
-		}
270
-		$cache = sous_repertoire(_DIR_VAR, $cache);
271
-		$cache = sous_repertoire($cache, $effet);
272
-	} else {
273
-		$fichier_dest = md5("$identifiant-$effet");
274
-		$cache = sous_repertoire(_DIR_VAR, $cache);
275
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
276
-		$fichier_dest = substr($fichier_dest, 2);
277
-	}
278
-
279
-	$fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
280
-
281
-	$GLOBALS["images_calculees"][] = $fichier_dest;
282
-
283
-	$creer = true;
284
-	// si recalcul des images demande, recalculer chaque image une fois
285
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
286
-		$images_recalcul[$fichier_dest] = true;
287
-	} else {
288
-		if (@file_exists($f = $fichier_dest)) {
289
-			if (filemtime($f) >= $date_src) {
290
-				$creer = false;
291
-			}
292
-		} else {
293
-			if (@file_exists($f = "$fichier_dest.src")
294
-				and lire_fichier($f, $valeurs)
295
-				and $valeurs = unserialize($valeurs)
296
-				and $valeurs["date"] >= $date_src
297
-			) {
298
-				$creer = false;
299
-			}
300
-		}
301
-	}
302
-	if ($creer) {
303
-		if (!@file_exists($fichier)) {
304
-			if (!@file_exists("$fichier.src")) {
305
-				spip_log("Image absente : $fichier");
306
-
307
-				return false;
308
-			}
309
-			# on reconstruit l'image source absente a partir de la chaine des .src
310
-			reconstruire_image_intermediaire($fichier);
311
-		}
312
-	}
313
-
314
-	if ($creer) {
315
-		spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
316
-			"images" . _LOG_DEBUG);
317
-	}
318
-
319
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
320
-	$ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
321
-	$ret["fichier"] = $fichier;
322
-	$ret["fonction_image"] = "_image_image" . $terminaison_dest;
323
-	$ret["fichier_dest"] = $fichier_dest;
324
-	$ret["format_source"] = _image_extension_normalisee($terminaison);
325
-	$ret["format_dest"] = $terminaison_dest;
326
-	$ret["date_src"] = $date_src;
327
-	$ret["creer"] = $creer;
328
-	$ret["class"] = extraire_attribut($img, 'class');
329
-	$ret["alt"] = extraire_attribut($img, 'alt');
330
-	$ret["style"] = extraire_attribut($img, 'style');
331
-	$ret["tag"] = $img;
332
-	if ($fonction_creation) {
333
-		$ret["reconstruction"] = $fonction_creation;
334
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
335
-		# cas de image_reduire qui finalement ne reduit pas l'image source
336
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
337
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
338
-	}
339
-
340
-	$ret = pipeline('image_preparer_filtre', array(
341
-			'args' => array(
342
-				'img' => $img,
343
-				'effet' => $effet,
344
-				'forcer_format' => $forcer_format,
345
-				'fonction_creation' => $fonction_creation,
346
-				'find_in_path' => $find_in_path,
347
-			),
348
-			'data' => $ret
349
-		)
350
-	);
351
-
352
-	// une globale pour le debug en cas de crash memoire
353
-	$GLOBALS["derniere_image_calculee"] = $ret;
354
-
355
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
356
-	if ($term_fonction === 'svg') {
357
-		if ($creer and !$support_svg) {
358
-			process_image_svg_identite($ret);
359
-			$ret['creer'] = false;
360
-		}
361
-	}
362
-	else {
363
-		if (!function_exists($ret["fonction_imagecreatefrom"])) {
364
-			return false;
365
-		}
366
-	}
367
-
368
-	return $ret;
151
+    static $images_recalcul = array();
152
+    if (strlen($img) == 0) {
153
+        return false;
154
+    }
155
+
156
+    $source = trim(extraire_attribut($img, 'src'));
157
+    if (strlen($source) < 1) {
158
+        $source = $img;
159
+        $img = "<img src='$source' />";
160
+    } # gerer img src="data:....base64"
161
+    elseif (preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
162
+      and $extension = _image_trouver_extension_depuis_mime("image/".$regs[1])
163
+        and in_array($extension, _image_extensions_acceptees_en_entree())
164
+    ) {
165
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
166
+        if (!file_exists($local)) {
167
+            ecrire_fichier($local, base64_decode($regs[2]));
168
+        }
169
+        $source = $local;
170
+        $img = inserer_attribut($img, 'src', $source);
171
+        # eviter les mauvaises surprises lors de conversions de format
172
+        $img = inserer_attribut($img, 'width', '');
173
+        $img = inserer_attribut($img, 'height', '');
174
+    }
175
+
176
+    // les protocoles web prennent au moins 3 lettres
177
+    if (tester_url_absolue($source)) {
178
+        include_spip('inc/distant');
179
+        $fichier = _DIR_RACINE . copie_locale($source);
180
+        if (!$fichier) {
181
+            return "";
182
+        }
183
+    } else {
184
+        // enlever le timestamp eventuel
185
+        if (strpos($source, "?") !== false) {
186
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
187
+        }
188
+        if (strpos($source, "?") !== false
189
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
190
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
191
+        ) {
192
+            $source = $f;
193
+        }
194
+        $fichier = $source;
195
+    }
196
+
197
+    $terminaison_dest = "";
198
+    if ($terminaison = _image_trouver_extension($fichier)) {
199
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
200
+    }
201
+
202
+    if ($forcer_format !== false
203
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
204
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format,_image_extensions_acceptees_en_sortie()))) {
205
+        $terminaison_dest = $forcer_format;
206
+    }
207
+
208
+    if (!$terminaison_dest) {
209
+        return false;
210
+    }
211
+
212
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
213
+    $fichier_dest = $nom_fichier;
214
+    if (($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
215
+        or @file_exists($f = $fichier)
216
+    ) {
217
+        // on passe la balise img a taille image qui exraira les attributs si possible
218
+        // au lieu de faire un acces disque sur le fichier
219
+        list($ret["hauteur"], $ret["largeur"]) = taille_image($find_in_path ? $f : $img);
220
+        $date_src = @filemtime($f);
221
+    } elseif (@file_exists($f = "$fichier.src")
222
+        and lire_fichier($f, $valeurs)
223
+        and $valeurs = unserialize($valeurs)
224
+        and isset($valeurs["hauteur_dest"])
225
+        and isset($valeurs["largeur_dest"])
226
+    ) {
227
+        $ret["hauteur"] = $valeurs["hauteur_dest"];
228
+        $ret["largeur"] = $valeurs["largeur_dest"];
229
+        $date_src = $valeurs["date"];
230
+    } // pas de fichier source par la
231
+    else {
232
+        return false;
233
+    }
234
+
235
+    // pas de taille mesurable
236
+    if (!($ret["hauteur"] or $ret["largeur"])) {
237
+        return false;
238
+    }
239
+
240
+    // les images calculees dependent du chemin du fichier source
241
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
242
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
243
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
244
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
245
+    // alors que ca concerne peu de site au final
246
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
247
+    $identifiant = $fichier;
248
+
249
+    // cas general :
250
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
251
+    // cas particulier de reduire :
252
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
253
+    $cache = "cache-gd2";
254
+    if (substr($effet, 0, 7) == 'reduire') {
255
+        list(, $maxWidth, $maxHeight) = explode('-', $effet);
256
+        list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
257
+        $ret['largeur_dest'] = $destWidth;
258
+        $ret['hauteur_dest'] = $destHeight;
259
+        $effet = "L{$destWidth}xH$destHeight";
260
+        $cache = "cache-vignettes";
261
+        $fichier_dest = basename($fichier_dest);
262
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
263
+            // on garde la terminaison initiale car image simplement copiee
264
+            // et on postfixe son nom avec un md5 du path
265
+            $terminaison_dest = $terminaison;
266
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
267
+        } else {
268
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
269
+        }
270
+        $cache = sous_repertoire(_DIR_VAR, $cache);
271
+        $cache = sous_repertoire($cache, $effet);
272
+    } else {
273
+        $fichier_dest = md5("$identifiant-$effet");
274
+        $cache = sous_repertoire(_DIR_VAR, $cache);
275
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
276
+        $fichier_dest = substr($fichier_dest, 2);
277
+    }
278
+
279
+    $fichier_dest = $cache . $fichier_dest . "." . $terminaison_dest;
280
+
281
+    $GLOBALS["images_calculees"][] = $fichier_dest;
282
+
283
+    $creer = true;
284
+    // si recalcul des images demande, recalculer chaque image une fois
285
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
286
+        $images_recalcul[$fichier_dest] = true;
287
+    } else {
288
+        if (@file_exists($f = $fichier_dest)) {
289
+            if (filemtime($f) >= $date_src) {
290
+                $creer = false;
291
+            }
292
+        } else {
293
+            if (@file_exists($f = "$fichier_dest.src")
294
+                and lire_fichier($f, $valeurs)
295
+                and $valeurs = unserialize($valeurs)
296
+                and $valeurs["date"] >= $date_src
297
+            ) {
298
+                $creer = false;
299
+            }
300
+        }
301
+    }
302
+    if ($creer) {
303
+        if (!@file_exists($fichier)) {
304
+            if (!@file_exists("$fichier.src")) {
305
+                spip_log("Image absente : $fichier");
306
+
307
+                return false;
308
+            }
309
+            # on reconstruit l'image source absente a partir de la chaine des .src
310
+            reconstruire_image_intermediaire($fichier);
311
+        }
312
+    }
313
+
314
+    if ($creer) {
315
+        spip_log("filtre image " . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
316
+            "images" . _LOG_DEBUG);
317
+    }
318
+
319
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
320
+    $ret["fonction_imagecreatefrom"] = "_imagecreatefrom" . $term_fonction;
321
+    $ret["fichier"] = $fichier;
322
+    $ret["fonction_image"] = "_image_image" . $terminaison_dest;
323
+    $ret["fichier_dest"] = $fichier_dest;
324
+    $ret["format_source"] = _image_extension_normalisee($terminaison);
325
+    $ret["format_dest"] = $terminaison_dest;
326
+    $ret["date_src"] = $date_src;
327
+    $ret["creer"] = $creer;
328
+    $ret["class"] = extraire_attribut($img, 'class');
329
+    $ret["alt"] = extraire_attribut($img, 'alt');
330
+    $ret["style"] = extraire_attribut($img, 'style');
331
+    $ret["tag"] = $img;
332
+    if ($fonction_creation) {
333
+        $ret["reconstruction"] = $fonction_creation;
334
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement 
335
+        # cas de image_reduire qui finalement ne reduit pas l'image source
336
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
337
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
338
+    }
339
+
340
+    $ret = pipeline('image_preparer_filtre', array(
341
+            'args' => array(
342
+                'img' => $img,
343
+                'effet' => $effet,
344
+                'forcer_format' => $forcer_format,
345
+                'fonction_creation' => $fonction_creation,
346
+                'find_in_path' => $find_in_path,
347
+            ),
348
+            'data' => $ret
349
+        )
350
+    );
351
+
352
+    // une globale pour le debug en cas de crash memoire
353
+    $GLOBALS["derniere_image_calculee"] = $ret;
354
+
355
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
356
+    if ($term_fonction === 'svg') {
357
+        if ($creer and !$support_svg) {
358
+            process_image_svg_identite($ret);
359
+            $ret['creer'] = false;
360
+        }
361
+    }
362
+    else {
363
+        if (!function_exists($ret["fonction_imagecreatefrom"])) {
364
+            return false;
365
+        }
366
+    }
367
+
368
+    return $ret;
369 369
 }
370 370
 
371 371
 
@@ -374,51 +374,51 @@  discard block
 block discarded – undo
374 374
  * @return array
375 375
  */
376 376
 function _image_extensions_acceptees_en_entree() {
377
-	static $extensions = null;
378
-	if (empty($extensions)) {
379
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
380
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
381
-			// action=tester renseigne gd_formats et detecte le support de webp
382
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
383
-			$extensions = array_map('trim', $extensions);
384
-			$extensions = array_filter($extensions);
385
-			$extensions = array_unique($extensions);
386
-		}
387
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
388
-	}
389
-
390
-	return $extensions;
377
+    static $extensions = null;
378
+    if (empty($extensions)) {
379
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
380
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
381
+            // action=tester renseigne gd_formats et detecte le support de webp
382
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
383
+            $extensions = array_map('trim', $extensions);
384
+            $extensions = array_filter($extensions);
385
+            $extensions = array_unique($extensions);
386
+        }
387
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
388
+    }
389
+
390
+    return $extensions;
391 391
 }
392 392
 
393 393
 /**
394 394
  * @return array|string[]|null
395 395
  */
396 396
 function _image_extensions_acceptees_en_sortie(){
397
-	static $extensions = null;
398
-	if (empty($extensions)){
399
-		$extensions = _image_extensions_acceptees_en_entree();
400
-		$extensions = array_diff($extensions, ['jpeg']);
401
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
402
-			$extensions = array_diff($extensions, ['gif']);
403
-		}
404
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
405
-			$extensions = array_diff($extensions, ['webp']);
406
-		}
407
-	}
408
-
409
-	return $extensions;
397
+    static $extensions = null;
398
+    if (empty($extensions)){
399
+        $extensions = _image_extensions_acceptees_en_entree();
400
+        $extensions = array_diff($extensions, ['jpeg']);
401
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
402
+            $extensions = array_diff($extensions, ['gif']);
403
+        }
404
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
405
+            $extensions = array_diff($extensions, ['webp']);
406
+        }
407
+    }
408
+
409
+    return $extensions;
410 410
 }
411 411
 
412 412
 function _image_extension_normalisee($extension){
413
-	$extension = strtolower($extension);
414
-	if ($extension === 'jpeg') {
415
-		$extension = 'jpg';
416
-	}
417
-	return $extension;
413
+    $extension = strtolower($extension);
414
+    if ($extension === 'jpeg') {
415
+        $extension = 'jpg';
416
+    }
417
+    return $extension;
418 418
 }
419 419
 
420 420
 function _image_extensions_conservent_transparence(){
421
-	return ['png', 'webp'];
421
+    return ['png', 'webp'];
422 422
 }
423 423
 
424 424
 
@@ -428,12 +428,12 @@  discard block
 block discarded – undo
428 428
  * @return string
429 429
  */
430 430
 function _image_trouver_extension($path) {
431
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
432
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
433
-		$terminaison = strtolower($regs[1]);
434
-		return $terminaison;
435
-	}
436
-	return '';
431
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
432
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
433
+        $terminaison = strtolower($regs[1]);
434
+        return $terminaison;
435
+    }
436
+    return '';
437 437
 }
438 438
 
439 439
 /**
@@ -444,33 +444,33 @@  discard block
 block discarded – undo
444 444
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
445 445
  */
446 446
 function _image_trouver_extension_pertinente($path) {
447
-	$path = supprimer_timestamp($path);
448
-	$terminaison = _image_trouver_extension($path);
449
-	if ($terminaison == 'jpg') {
450
-		$terminaison = 'jpeg';
451
-	}
452
-
453
-	if (!file_exists($path)) {
454
-		return $terminaison;
455
-	}
456
-
457
-	if (!$info = @spip_getimagesize($path)) {
458
-		return $terminaison;
459
-	}
460
-
461
-	if (isset($info['mime'])) {
462
-		$mime = $info['mime'];
463
-	}
464
-	else {
465
-		$mime = image_type_to_mime_type($info[2]);
466
-	}
467
-
468
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
469
-	if ($_terminaison and $_terminaison !== $terminaison) {
470
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
471
-		$terminaison = $_terminaison;
472
-	}
473
-	return $terminaison;
447
+    $path = supprimer_timestamp($path);
448
+    $terminaison = _image_trouver_extension($path);
449
+    if ($terminaison == 'jpg') {
450
+        $terminaison = 'jpeg';
451
+    }
452
+
453
+    if (!file_exists($path)) {
454
+        return $terminaison;
455
+    }
456
+
457
+    if (!$info = @spip_getimagesize($path)) {
458
+        return $terminaison;
459
+    }
460
+
461
+    if (isset($info['mime'])) {
462
+        $mime = $info['mime'];
463
+    }
464
+    else {
465
+        $mime = image_type_to_mime_type($info[2]);
466
+    }
467
+
468
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
469
+    if ($_terminaison and $_terminaison !== $terminaison) {
470
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", "images." . _LOG_INFO_IMPORTANTE);
471
+        $terminaison = $_terminaison;
472
+    }
473
+    return $terminaison;
474 474
 }
475 475
 
476 476
 /**
@@ -478,36 +478,36 @@  discard block
 block discarded – undo
478 478
  * @return string
479 479
  */
480 480
 function _image_trouver_extension_depuis_mime($mime) {
481
-	switch (strtolower($mime)) {
482
-		case 'image/png':
483
-		case 'image/x-png':
484
-			$terminaison = 'png';
485
-			break;
486
-
487
-		case 'image/jpg':
488
-		case 'image/jpeg':
489
-		case 'image/pjpeg':
490
-			$terminaison = 'jpeg';
491
-			break;
492
-
493
-		case 'image/gif':
494
-			$terminaison = 'gif';
495
-			break;
496
-
497
-		case 'image/webp':
498
-		case 'image/x-webp':
499
-			$terminaison = 'webp';
500
-			break;
501
-
502
-		case 'image/svg+xml':
503
-			$terminaison = 'svg';
504
-			break;
505
-
506
-		default:
507
-			$terminaison = '';
508
-	}
509
-
510
-	return $terminaison;
481
+    switch (strtolower($mime)) {
482
+        case 'image/png':
483
+        case 'image/x-png':
484
+            $terminaison = 'png';
485
+            break;
486
+
487
+        case 'image/jpg':
488
+        case 'image/jpeg':
489
+        case 'image/pjpeg':
490
+            $terminaison = 'jpeg';
491
+            break;
492
+
493
+        case 'image/gif':
494
+            $terminaison = 'gif';
495
+            break;
496
+
497
+        case 'image/webp':
498
+        case 'image/x-webp':
499
+            $terminaison = 'webp';
500
+            break;
501
+
502
+        case 'image/svg+xml':
503
+            $terminaison = 'svg';
504
+            break;
505
+
506
+        default:
507
+            $terminaison = '';
508
+    }
509
+
510
+    return $terminaison;
511 511
 }
512 512
 
513 513
 /**
@@ -522,14 +522,14 @@  discard block
 block discarded – undo
522 522
  *     Une ressource de type Image GD.
523 523
  */
524 524
 function _imagecreatefromjpeg($filename) {
525
-	$img = @imagecreatefromjpeg($filename);
526
-	if (!$img) {
527
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
528
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
529
-		$img = imagecreate(10, 10);
530
-	}
531
-
532
-	return $img;
525
+    $img = @imagecreatefromjpeg($filename);
526
+    if (!$img) {
527
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
528
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
529
+        $img = imagecreate(10, 10);
530
+    }
531
+
532
+    return $img;
533 533
 }
534 534
 
535 535
 /**
@@ -544,14 +544,14 @@  discard block
 block discarded – undo
544 544
  *     Une ressource de type Image GD.
545 545
  */
546 546
 function _imagecreatefrompng($filename) {
547
-	$img = @imagecreatefrompng($filename);
548
-	if (!$img) {
549
-		spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
550
-		erreur_squelette("Erreur lecture imagecreatefrompng $filename");
551
-		$img = imagecreate(10, 10);
552
-	}
553
-
554
-	return $img;
547
+    $img = @imagecreatefrompng($filename);
548
+    if (!$img) {
549
+        spip_log("Erreur lecture imagecreatefrompng $filename", _LOG_CRITIQUE);
550
+        erreur_squelette("Erreur lecture imagecreatefrompng $filename");
551
+        $img = imagecreate(10, 10);
552
+    }
553
+
554
+    return $img;
555 555
 }
556 556
 
557 557
 /**
@@ -566,14 +566,14 @@  discard block
 block discarded – undo
566 566
  *     Une ressource de type Image GD.
567 567
  */
568 568
 function _imagecreatefromgif($filename) {
569
-	$img = @imagecreatefromgif($filename);
570
-	if (!$img) {
571
-		spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
572
-		erreur_squelette("Erreur lecture imagecreatefromgif $filename");
573
-		$img = imagecreate(10, 10);
574
-	}
575
-
576
-	return $img;
569
+    $img = @imagecreatefromgif($filename);
570
+    if (!$img) {
571
+        spip_log("Erreur lecture imagecreatefromgif $filename", _LOG_CRITIQUE);
572
+        erreur_squelette("Erreur lecture imagecreatefromgif $filename");
573
+        $img = imagecreate(10, 10);
574
+    }
575
+
576
+    return $img;
577 577
 }
578 578
 
579 579
 
@@ -589,14 +589,14 @@  discard block
 block discarded – undo
589 589
  *     Une ressource de type Image GD.
590 590
  */
591 591
 function _imagecreatefromwebp($filename) {
592
-	$img = @imagecreatefromwebp($filename);
593
-	if (!$img) {
594
-		spip_log("Erreur lecture imagecreatefromwebp $filename", _LOG_CRITIQUE);
595
-		erreur_squelette("Erreur lecture imagecreatefrompng $filename");
596
-		$img = imagecreate(10, 10);
597
-	}
598
-
599
-	return $img;
592
+    $img = @imagecreatefromwebp($filename);
593
+    if (!$img) {
594
+        spip_log("Erreur lecture imagecreatefromwebp $filename", _LOG_CRITIQUE);
595
+        erreur_squelette("Erreur lecture imagecreatefrompng $filename");
596
+        $img = imagecreate(10, 10);
597
+    }
598
+
599
+    return $img;
600 600
 }
601 601
 
602 602
 /**
@@ -614,24 +614,24 @@  discard block
 block discarded – undo
614 614
  *     - true si une image est bien retournée.
615 615
  */
616 616
 function _image_imagepng($img, $fichier) {
617
-	if (!function_exists('imagepng')) {
618
-		return false;
619
-	}
620
-	$tmp = $fichier . ".tmp";
621
-	$ret = imagepng($img, $tmp);
622
-	if (file_exists($tmp)) {
623
-		$taille_test = getimagesize($tmp);
624
-		if ($taille_test[0] < 1) {
625
-			return false;
626
-		}
627
-
628
-		spip_unlink($fichier); // le fichier peut deja exister
629
-		@rename($tmp, $fichier);
630
-
631
-		return $ret;
632
-	}
633
-
634
-	return false;
617
+    if (!function_exists('imagepng')) {
618
+        return false;
619
+    }
620
+    $tmp = $fichier . ".tmp";
621
+    $ret = imagepng($img, $tmp);
622
+    if (file_exists($tmp)) {
623
+        $taille_test = getimagesize($tmp);
624
+        if ($taille_test[0] < 1) {
625
+            return false;
626
+        }
627
+
628
+        spip_unlink($fichier); // le fichier peut deja exister
629
+        @rename($tmp, $fichier);
630
+
631
+        return $ret;
632
+    }
633
+
634
+    return false;
635 635
 }
636 636
 
637 637
 /**
@@ -649,24 +649,24 @@  discard block
 block discarded – undo
649 649
  *     - true si une image est bien retournée.
650 650
  */
651 651
 function _image_imagegif($img, $fichier) {
652
-	if (!function_exists('imagegif')) {
653
-		return false;
654
-	}
655
-	$tmp = $fichier . ".tmp";
656
-	$ret = imagegif($img, $tmp);
657
-	if (file_exists($tmp)) {
658
-		$taille_test = getimagesize($tmp);
659
-		if ($taille_test[0] < 1) {
660
-			return false;
661
-		}
662
-
663
-		spip_unlink($fichier); // le fichier peut deja exister
664
-		@rename($tmp, $fichier);
665
-
666
-		return $ret;
667
-	}
668
-
669
-	return false;
652
+    if (!function_exists('imagegif')) {
653
+        return false;
654
+    }
655
+    $tmp = $fichier . ".tmp";
656
+    $ret = imagegif($img, $tmp);
657
+    if (file_exists($tmp)) {
658
+        $taille_test = getimagesize($tmp);
659
+        if ($taille_test[0] < 1) {
660
+            return false;
661
+        }
662
+
663
+        spip_unlink($fichier); // le fichier peut deja exister
664
+        @rename($tmp, $fichier);
665
+
666
+        return $ret;
667
+    }
668
+
669
+    return false;
670 670
 }
671 671
 
672 672
 /**
@@ -689,29 +689,29 @@  discard block
 block discarded – undo
689 689
  *     - true si une image est bien retournée.
690 690
  */
691 691
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
692
-	if (!function_exists('imagejpeg')) {
693
-		return false;
694
-	}
695
-	$tmp = $fichier . ".tmp";
692
+    if (!function_exists('imagejpeg')) {
693
+        return false;
694
+    }
695
+    $tmp = $fichier . ".tmp";
696 696
 
697
-	// Enable interlancing
698
-	imageinterlace($img, true);
697
+    // Enable interlancing
698
+    imageinterlace($img, true);
699 699
 
700
-	$ret = imagejpeg($img, $tmp, $qualite);
700
+    $ret = imagejpeg($img, $tmp, $qualite);
701 701
 
702
-	if (file_exists($tmp)) {
703
-		$taille_test = getimagesize($tmp);
704
-		if ($taille_test[0] < 1) {
705
-			return false;
706
-		}
702
+    if (file_exists($tmp)) {
703
+        $taille_test = getimagesize($tmp);
704
+        if ($taille_test[0] < 1) {
705
+            return false;
706
+        }
707 707
 
708
-		spip_unlink($fichier); // le fichier peut deja exister
709
-		@rename($tmp, $fichier);
708
+        spip_unlink($fichier); // le fichier peut deja exister
709
+        @rename($tmp, $fichier);
710 710
 
711
-		return $ret;
712
-	}
711
+        return $ret;
712
+    }
713 713
 
714
-	return false;
714
+    return false;
715 715
 }
716 716
 
717 717
 /**
@@ -729,9 +729,9 @@  discard block
 block discarded – undo
729 729
  *     true si le fichier a bien été créé ; false sinon.
730 730
  */
731 731
 function _image_imageico($img, $fichier) {
732
-	$gd_image_array = array($img);
732
+    $gd_image_array = array($img);
733 733
 
734
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
734
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
735 735
 }
736 736
 
737 737
 
@@ -750,24 +750,24 @@  discard block
 block discarded – undo
750 750
  *     - true si une image est bien retournée.
751 751
  */
752 752
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
753
-	if (!function_exists('imagewebp')) {
754
-		return false;
755
-	}
756
-	$tmp = $fichier . ".tmp";
757
-	$ret = imagewebp($img, $tmp, $qualite);
758
-	if (file_exists($tmp)) {
759
-		$taille_test = getimagesize($tmp);
760
-		if ($taille_test[0] < 1) {
761
-			return false;
762
-		}
763
-
764
-		spip_unlink($fichier); // le fichier peut deja exister
765
-		@rename($tmp, $fichier);
766
-
767
-		return $ret;
768
-	}
769
-
770
-	return false;
753
+    if (!function_exists('imagewebp')) {
754
+        return false;
755
+    }
756
+    $tmp = $fichier . ".tmp";
757
+    $ret = imagewebp($img, $tmp, $qualite);
758
+    if (file_exists($tmp)) {
759
+        $taille_test = getimagesize($tmp);
760
+        if ($taille_test[0] < 1) {
761
+            return false;
762
+        }
763
+
764
+        spip_unlink($fichier); // le fichier peut deja exister
765
+        @rename($tmp, $fichier);
766
+
767
+        return $ret;
768
+    }
769
+
770
+    return false;
771 771
 }
772 772
 
773 773
 /**
@@ -787,35 +787,35 @@  discard block
 block discarded – undo
787 787
  */
788 788
 function _image_imagesvg($img, $fichier) {
789 789
 
790
-	$tmp = $fichier . ".tmp";
791
-	if (strpos($img, "<") === false) {
792
-		$img = supprimer_timestamp($img);
793
-		if (!file_exists($img)) {
794
-			return false;
795
-		}
796
-		@copy($img, $tmp);
797
-		if (filesize($tmp) == filesize($img)) {
798
-			spip_unlink($fichier); // le fichier peut deja exister
799
-			@rename($tmp, $fichier);
800
-			return true;
801
-		}
802
-		return false;
803
-	}
804
-
805
-	file_put_contents($tmp, $img);
806
-	if (file_exists($tmp)) {
807
-		$taille_test = spip_getimagesize($tmp);
808
-		if ($taille_test[0] < 1) {
809
-			return false;
810
-		}
811
-
812
-		spip_unlink($fichier); // le fichier peut deja exister
813
-		@rename($tmp, $fichier);
814
-
815
-		return true;
816
-	}
817
-
818
-	return false;
790
+    $tmp = $fichier . ".tmp";
791
+    if (strpos($img, "<") === false) {
792
+        $img = supprimer_timestamp($img);
793
+        if (!file_exists($img)) {
794
+            return false;
795
+        }
796
+        @copy($img, $tmp);
797
+        if (filesize($tmp) == filesize($img)) {
798
+            spip_unlink($fichier); // le fichier peut deja exister
799
+            @rename($tmp, $fichier);
800
+            return true;
801
+        }
802
+        return false;
803
+    }
804
+
805
+    file_put_contents($tmp, $img);
806
+    if (file_exists($tmp)) {
807
+        $taille_test = spip_getimagesize($tmp);
808
+        if ($taille_test[0] < 1) {
809
+            return false;
810
+        }
811
+
812
+        spip_unlink($fichier); // le fichier peut deja exister
813
+        @rename($tmp, $fichier);
814
+
815
+        return true;
816
+    }
817
+
818
+    return false;
819 819
 }
820 820
 
821 821
 
@@ -843,27 +843,27 @@  discard block
 block discarded – undo
843 843
  *     - false sinon.
844 844
  */
845 845
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE) {
846
-	$fonction = "_image_image" . $valeurs['format_dest'];
847
-	$ret = false;
848
-	#un flag pour reperer les images gravees
849
-	$lock =
850
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
851
-	or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
852
-	if (
853
-		function_exists($fonction)
854
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
855
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
856
-		&& !$lock
857
-	) {
858
-		if (@file_exists($valeurs['fichier_dest'])) {
859
-			// dans tous les cas mettre a jour la taille de l'image finale
860
-			list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
861
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
862
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
863
-		}
864
-	}
865
-
866
-	return $ret;
846
+    $fonction = "_image_image" . $valeurs['format_dest'];
847
+    $ret = false;
848
+    #un flag pour reperer les images gravees
849
+    $lock =
850
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
851
+    or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'));
852
+    if (
853
+        function_exists($fonction)
854
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
855
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
856
+        && !$lock
857
+    ) {
858
+        if (@file_exists($valeurs['fichier_dest'])) {
859
+            // dans tous les cas mettre a jour la taille de l'image finale
860
+            list($valeurs["hauteur_dest"], $valeurs["largeur_dest"]) = taille_image($valeurs['fichier_dest']);
861
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
862
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
863
+        }
864
+    }
865
+
866
+    return $ret;
867 867
 }
868 868
 
869 869
 /**
@@ -876,26 +876,26 @@  discard block
 block discarded – undo
876 876
  *     Chemin vers le fichier manquant
877 877
  **/
878 878
 function reconstruire_image_intermediaire($fichier_manquant) {
879
-	$reconstruire = array();
880
-	$fichier = $fichier_manquant;
881
-	while (strpos($fichier,"://")===false
882
-		and !@file_exists($fichier)
883
-		and lire_fichier($src = "$fichier.src", $source)
884
-		and $valeurs = unserialize($source)
885
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
886
-	) {
887
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
888
-		$reconstruire[] = $valeurs['reconstruction'];
889
-	}
890
-	while (count($reconstruire)) {
891
-		$r = array_pop($reconstruire);
892
-		$fonction = $r[0];
893
-		$args = $r[1];
894
-		call_user_func_array($fonction, $args);
895
-	}
896
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
897
-	// mais l'on peut nettoyer les miettes de sa creation
898
-	ramasse_miettes($fichier_manquant);
879
+    $reconstruire = array();
880
+    $fichier = $fichier_manquant;
881
+    while (strpos($fichier,"://")===false
882
+        and !@file_exists($fichier)
883
+        and lire_fichier($src = "$fichier.src", $source)
884
+        and $valeurs = unserialize($source)
885
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
886
+    ) {
887
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
888
+        $reconstruire[] = $valeurs['reconstruction'];
889
+    }
890
+    while (count($reconstruire)) {
891
+        $r = array_pop($reconstruire);
892
+        $fonction = $r[0];
893
+        $args = $r[1];
894
+        call_user_func_array($fonction, $args);
895
+    }
896
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
897
+    // mais l'on peut nettoyer les miettes de sa creation
898
+    ramasse_miettes($fichier_manquant);
899 899
 }
900 900
 
901 901
 /**
@@ -915,25 +915,25 @@  discard block
 block discarded – undo
915 915
  *     Chemin du fichier d'image calculé
916 916
  **/
917 917
 function ramasse_miettes($fichier) {
918
-	if (strpos($fichier,"://")!==false
919
-		or !lire_fichier($src = "$fichier.src", $source)
920
-		or !$valeurs = unserialize($source)
921
-	) {
922
-		return;
923
-	}
924
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
925
-	while (
926
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
927
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
928
-		and (lire_fichier($src = "$fichier.src",
929
-			$source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
930
-		and ($valeurs = unserialize($source))  # et valide
931
-	) {
932
-		# on efface le fichier
933
-		spip_unlink($fichier);
934
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
935
-		#spip_unlink($src);
936
-	}
918
+    if (strpos($fichier,"://")!==false
919
+        or !lire_fichier($src = "$fichier.src", $source)
920
+        or !$valeurs = unserialize($source)
921
+    ) {
922
+        return;
923
+    }
924
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
925
+    while (
926
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
927
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
928
+        and (lire_fichier($src = "$fichier.src",
929
+            $source)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
930
+        and ($valeurs = unserialize($source))  # et valide
931
+    ) {
932
+        # on efface le fichier
933
+        spip_unlink($fichier);
934
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
935
+        #spip_unlink($src);
936
+    }
937 937
 }
938 938
 
939 939
 
@@ -958,71 +958,71 @@  discard block
 block discarded – undo
958 958
  *     Code HTML de l'image
959 959
  **/
960 960
 function image_graver($img) {
961
-	// appeler le filtre post_image_filtrer qui permet de faire
962
-	// des traitements auto a la fin d'une serie de filtres
963
-	$img = pipeline('post_image_filtrer', $img);
964
-
965
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
966
-	if (($p = strpos($fichier, '?')) !== false) {
967
-		$fichier = substr($fichier, 0, $p);
968
-	}
969
-	if (strlen($fichier) < 1) {
970
-		$fichier = $img;
971
-	}
972
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
973
-	# et qu'il ne s'agit pas d'une URL
974
-	if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
975
-		reconstruire_image_intermediaire($fichier);
976
-	}
977
-	ramasse_miettes($fichier);
978
-
979
-	// ajouter le timestamp si besoin
980
-	if (strpos($fichier_ori, "?") === false) {
981
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
982
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
983
-	}
984
-
985
-	return $img;
961
+    // appeler le filtre post_image_filtrer qui permet de faire
962
+    // des traitements auto a la fin d'une serie de filtres
963
+    $img = pipeline('post_image_filtrer', $img);
964
+
965
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
966
+    if (($p = strpos($fichier, '?')) !== false) {
967
+        $fichier = substr($fichier, 0, $p);
968
+    }
969
+    if (strlen($fichier) < 1) {
970
+        $fichier = $img;
971
+    }
972
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
973
+    # et qu'il ne s'agit pas d'une URL
974
+    if (strpos($fichier,"://")===false and !@file_exists($fichier)) {
975
+        reconstruire_image_intermediaire($fichier);
976
+    }
977
+    ramasse_miettes($fichier);
978
+
979
+    // ajouter le timestamp si besoin
980
+    if (strpos($fichier_ori, "?") === false) {
981
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
982
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
983
+    }
984
+
985
+    return $img;
986 986
 }
987 987
 
988 988
 
989 989
 if (!function_exists("imagepalettetotruecolor")) {
990
-	/**
991
-	 * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
992
-	 *
993
-	 * @note Pour compatibilité avec PHP < 5.5
994
-	 *
995
-	 * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
996
-	 *
997
-	 * @param ressource $img
998
-	 * @return bool
999
-	 *     - true si l'image est déjà en vrai RGB ou peut être transformée
1000
-	 *     - false si la transformation ne peut être faite.
1001
-	 **/
1002
-	function imagepalettetotruecolor(&$img) {
1003
-		if (!$img or !function_exists('imagecreatetruecolor')) {
1004
-			return false;
1005
-		} elseif (!imageistruecolor($img)) {
1006
-			$w = imagesx($img);
1007
-			$h = imagesy($img);
1008
-			$img1 = imagecreatetruecolor($w, $h);
1009
-			//Conserver la transparence si possible
1010
-			if (function_exists('ImageCopyResampled')) {
1011
-				if (function_exists("imageAntiAlias")) {
1012
-					imageAntiAlias($img1, true);
1013
-				}
1014
-				@imagealphablending($img1, false);
1015
-				@imagesavealpha($img1, true);
1016
-				@ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1017
-			} else {
1018
-				imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1019
-			}
1020
-
1021
-			$img = $img1;
1022
-		}
1023
-
1024
-		return true;
1025
-	}
990
+    /**
991
+     * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB
992
+     *
993
+     * @note Pour compatibilité avec PHP < 5.5
994
+     *
995
+     * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php
996
+     *
997
+     * @param ressource $img
998
+     * @return bool
999
+     *     - true si l'image est déjà en vrai RGB ou peut être transformée
1000
+     *     - false si la transformation ne peut être faite.
1001
+     **/
1002
+    function imagepalettetotruecolor(&$img) {
1003
+        if (!$img or !function_exists('imagecreatetruecolor')) {
1004
+            return false;
1005
+        } elseif (!imageistruecolor($img)) {
1006
+            $w = imagesx($img);
1007
+            $h = imagesy($img);
1008
+            $img1 = imagecreatetruecolor($w, $h);
1009
+            //Conserver la transparence si possible
1010
+            if (function_exists('ImageCopyResampled')) {
1011
+                if (function_exists("imageAntiAlias")) {
1012
+                    imageAntiAlias($img1, true);
1013
+                }
1014
+                @imagealphablending($img1, false);
1015
+                @imagesavealpha($img1, true);
1016
+                @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h);
1017
+            } else {
1018
+                imagecopy($img1, $img, 0, 0, 0, 0, $w, $h);
1019
+            }
1020
+
1021
+            $img = $img1;
1022
+        }
1023
+
1024
+        return true;
1025
+    }
1026 1026
 }
1027 1027
 
1028 1028
 /**
@@ -1049,32 +1049,32 @@  discard block
 block discarded – undo
1049 1049
  *     Code html modifié de la balise.
1050 1050
  **/
1051 1051
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1052
-	if ($style === false) {
1053
-		$style = extraire_attribut($tag, 'style');
1054
-	}
1055
-
1056
-	// enlever le width et height du style
1057
-	$style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
1058
-	if ($style and $style[0] == ';') {
1059
-		$style = substr($style, 1);
1060
-	}
1061
-
1062
-	// mettre des attributs de width et height sur les images, 
1063
-	// ca accelere le rendu du navigateur
1064
-	// ca permet aux navigateurs de reserver la bonne taille 
1065
-	// quand on a desactive l'affichage des images.
1066
-	$tag = inserer_attribut($tag, 'width', round($width));
1067
-	$tag = inserer_attribut($tag, 'height', round($height));
1068
-
1069
-	// attributs deprecies. Transformer en CSS
1070
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1071
-		$style = "margin:${espace}px;" . $style;
1072
-		$tag = inserer_attribut($tag, 'hspace', '');
1073
-	}
1074
-
1075
-	$tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
1076
-
1077
-	return $tag;
1052
+    if ($style === false) {
1053
+        $style = extraire_attribut($tag, 'style');
1054
+    }
1055
+
1056
+    // enlever le width et height du style
1057
+    $style = preg_replace(",(^|;)\s*(width|height)\s*:\s*[^;]+,ims", "", $style);
1058
+    if ($style and $style[0] == ';') {
1059
+        $style = substr($style, 1);
1060
+    }
1061
+
1062
+    // mettre des attributs de width et height sur les images, 
1063
+    // ca accelere le rendu du navigateur
1064
+    // ca permet aux navigateurs de reserver la bonne taille 
1065
+    // quand on a desactive l'affichage des images.
1066
+    $tag = inserer_attribut($tag, 'width', round($width));
1067
+    $tag = inserer_attribut($tag, 'height', round($height));
1068
+
1069
+    // attributs deprecies. Transformer en CSS
1070
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1071
+        $style = "margin:${espace}px;" . $style;
1072
+        $tag = inserer_attribut($tag, 'hspace', '');
1073
+    }
1074
+
1075
+    $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true);
1076
+
1077
+    return $tag;
1078 1078
 }
1079 1079
 
1080 1080
 
@@ -1100,71 +1100,71 @@  discard block
 block discarded – undo
1100 1100
  *     Retourne le code HTML de l'image
1101 1101
  **/
1102 1102
 function _image_ecrire_tag($valeurs, $surcharge = array()) {
1103
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1104
-
1105
-	// fermer les tags img pas bien fermes;
1106
-	$tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag']));
1107
-
1108
-	// le style
1109
-	$style = $valeurs['style'];
1110
-	if (isset($surcharge['style'])) {
1111
-		$style = $surcharge['style'];
1112
-		unset($surcharge['style']);
1113
-	}
1114
-
1115
-	// traiter specifiquement la largeur et la hauteur
1116
-	$width = $valeurs['largeur'];
1117
-	if (isset($surcharge['width'])) {
1118
-		$width = $surcharge['width'];
1119
-		unset($surcharge['width']);
1120
-	}
1121
-	$height = $valeurs['hauteur'];
1122
-	if (isset($surcharge['height'])) {
1123
-		$height = $surcharge['height'];
1124
-		unset($surcharge['height']);
1125
-	}
1126
-
1127
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1128
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1129
-	// on remplace toute les ref a src dans le tag
1130
-	$src = extraire_attribut($tag, 'src');
1131
-	if (isset($surcharge['src'])) {
1132
-		$tag = str_replace($src, $surcharge['src'], $tag);
1133
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1134
-		// pas garanti comme methode, mais mieux que rien
1135
-		if (strpos($src, '&') !== false) {
1136
-			$tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
1137
-		}
1138
-		$src = $surcharge['src'];
1139
-		unset($surcharge['src']);
1140
-	}
1141
-
1142
-	$class = $valeurs['class'];
1143
-	if (isset($surcharge['class'])) {
1144
-		$class = $surcharge['class'];
1145
-		unset($surcharge['class']);
1146
-	}
1147
-	if (strlen($class)) {
1148
-		$tag = inserer_attribut($tag, 'class', $class);
1149
-	}
1150
-
1151
-	if (count($surcharge)) {
1152
-		foreach ($surcharge as $attribut => $valeur) {
1153
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1154
-		}
1155
-	}
1156
-
1157
-	$tag = pipeline('image_ecrire_tag_finir',
1158
-		array(
1159
-			'args' => array(
1160
-				'valeurs' => $valeurs,
1161
-				'surcharge' => $surcharge,
1162
-			),
1163
-			'data' => $tag
1164
-		)
1165
-	);
1166
-
1167
-	return $tag;
1103
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1104
+
1105
+    // fermer les tags img pas bien fermes;
1106
+    $tag = str_replace(">", "/>", str_replace("/>", ">", $valeurs['tag']));
1107
+
1108
+    // le style
1109
+    $style = $valeurs['style'];
1110
+    if (isset($surcharge['style'])) {
1111
+        $style = $surcharge['style'];
1112
+        unset($surcharge['style']);
1113
+    }
1114
+
1115
+    // traiter specifiquement la largeur et la hauteur
1116
+    $width = $valeurs['largeur'];
1117
+    if (isset($surcharge['width'])) {
1118
+        $width = $surcharge['width'];
1119
+        unset($surcharge['width']);
1120
+    }
1121
+    $height = $valeurs['hauteur'];
1122
+    if (isset($surcharge['height'])) {
1123
+        $height = $surcharge['height'];
1124
+        unset($surcharge['height']);
1125
+    }
1126
+
1127
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1128
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1129
+    // on remplace toute les ref a src dans le tag
1130
+    $src = extraire_attribut($tag, 'src');
1131
+    if (isset($surcharge['src'])) {
1132
+        $tag = str_replace($src, $surcharge['src'], $tag);
1133
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1134
+        // pas garanti comme methode, mais mieux que rien
1135
+        if (strpos($src, '&') !== false) {
1136
+            $tag = str_replace(str_replace("&", "&amp;", $src), $surcharge['src'], $tag);
1137
+        }
1138
+        $src = $surcharge['src'];
1139
+        unset($surcharge['src']);
1140
+    }
1141
+
1142
+    $class = $valeurs['class'];
1143
+    if (isset($surcharge['class'])) {
1144
+        $class = $surcharge['class'];
1145
+        unset($surcharge['class']);
1146
+    }
1147
+    if (strlen($class)) {
1148
+        $tag = inserer_attribut($tag, 'class', $class);
1149
+    }
1150
+
1151
+    if (count($surcharge)) {
1152
+        foreach ($surcharge as $attribut => $valeur) {
1153
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1154
+        }
1155
+    }
1156
+
1157
+    $tag = pipeline('image_ecrire_tag_finir',
1158
+        array(
1159
+            'args' => array(
1160
+                'valeurs' => $valeurs,
1161
+                'surcharge' => $surcharge,
1162
+            ),
1163
+            'data' => $tag
1164
+        )
1165
+    );
1166
+
1167
+    return $tag;
1168 1168
 }
1169 1169
 
1170 1170
 /**
@@ -1187,253 +1187,253 @@  discard block
 block discarded – undo
1187 1187
  *     Description de l'image, sinon null.
1188 1188
  **/
1189 1189
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1190
-	// ordre de preference des formats graphiques pour creer les vignettes
1191
-	// le premier format disponible, selon la methode demandee, est utilise
1192
-	$image = $valeurs['fichier'];
1193
-	$format = $valeurs['format_source'];
1194
-	$destdir = dirname($valeurs['fichier_dest']);
1195
-	$destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
1196
-
1197
-	$format_sortie = $valeurs['format_dest'];
1198
-
1199
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1200
-		$process = $GLOBALS['meta']['image_process'];
1201
-	}
1202
-
1203
-	// si le doc n'est pas une image dans un format accetpable, refuser
1204
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1205
-		return;
1206
-	}
1207
-	$destination = "$destdir/$destfile";
1208
-
1209
-	// calculer la taille
1210
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1211
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1212
-			list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1213
-		}
1214
-	} elseif ($process == 'convert' or $process == 'imagick') {
1215
-		$destWidth = $maxWidth;
1216
-		$destHeight = $maxHeight;
1217
-	} else {
1218
-		spip_log("echec $process sur $image");
1219
-
1220
-		return;
1221
-	}
1222
-
1223
-	$vignette = '';
1224
-
1225
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1226
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1227
-		$vignette = $destination . '.' . $format;
1228
-		@copy($image, $vignette);
1229
-	}
1230
-
1231
-	elseif ($valeurs["format_source"] === 'svg') {
1232
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){
1233
-			$format_sortie = 'svg';
1234
-			$vignette = $destination . "." . $format_sortie;
1235
-			$valeurs['fichier_dest'] = $vignette;
1236
-			_image_gd_output($svg, $valeurs);
1237
-		}
1238
-	}
1239
-
1240
-	// imagemagick en ligne de commande
1241
-	elseif ($process == 'convert') {
1242
-		if (!defined('_CONVERT_COMMAND')) {
1243
-			define('_CONVERT_COMMAND', 'convert');
1244
-		} // Securite : mes_options.php peut preciser le chemin absolu
1245
-		if (!defined('_RESIZE_COMMAND')) {
1246
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1247
-		}
1248
-		$vignette = $destination . "." . $format_sortie;
1249
-		$commande = str_replace(
1250
-			array('%x', '%y', '%src', '%dest'),
1251
-			array(
1252
-				$destWidth,
1253
-				$destHeight,
1254
-				escapeshellcmd($image),
1255
-				escapeshellcmd($vignette)
1256
-			),
1257
-			_RESIZE_COMMAND);
1258
-		spip_log($commande);
1259
-		exec($commande);
1260
-		if (!@file_exists($vignette)) {
1261
-			spip_log("echec convert sur $vignette");
1262
-
1263
-			return;  // echec commande
1264
-		}
1265
-	}
1266
-
1267
-	// php5 imagemagick
1268
-	elseif ($process == 'imagick') {
1269
-		$vignette = "$destination." . $format_sortie;
1270
-
1271
-		if (!class_exists('Imagick')) {
1272
-			spip_log("Classe Imagick absente !", _LOG_ERREUR);
1273
-
1274
-			return;
1275
-		}
1276
-		$imagick = new Imagick();
1277
-		$imagick->readImage($image);
1278
-		$imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1279
-			1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1280
-		$imagick->writeImage($vignette);
1281
-
1282
-		if (!@file_exists($vignette)) {
1283
-			spip_log("echec imagick sur $vignette");
1284
-
1285
-			return;
1286
-		}
1287
-	}
1288
-
1289
-	// netpbm
1290
-	elseif ($process == "netpbm") {
1291
-		if (!defined('_PNMSCALE_COMMAND')) {
1292
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1293
-		} // Securite : mes_options.php peut preciser le chemin absolu
1294
-		if (_PNMSCALE_COMMAND == '') {
1295
-			return;
1296
-		}
1297
-		$vignette = $destination . "." . $format_sortie;
1298
-		$pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1299
-		if ($format == "jpg") {
1300
-
1301
-			$jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1302
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1303
-			if (!($s = @filesize($vignette))) {
1304
-				spip_unlink($vignette);
1305
-			}
1306
-			if (!@file_exists($vignette)) {
1307
-				spip_log("echec netpbm-jpg sur $vignette");
1308
-
1309
-				return;
1310
-			}
1311
-		} else {
1312
-			if ($format == "gif") {
1313
-				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1314
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1315
-				if (!($s = @filesize($vignette))) {
1316
-					spip_unlink($vignette);
1317
-				}
1318
-				if (!@file_exists($vignette)) {
1319
-					spip_log("echec netpbm-gif sur $vignette");
1320
-
1321
-					return;
1322
-				}
1323
-			} else {
1324
-				if ($format == "png") {
1325
-					$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1326
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1327
-					if (!($s = @filesize($vignette))) {
1328
-						spip_unlink($vignette);
1329
-					}
1330
-					if (!@file_exists($vignette)) {
1331
-						spip_log("echec netpbm-png sur $vignette");
1332
-
1333
-						return;
1334
-					}
1335
-				}
1336
-			}
1337
-		}
1338
-	}
1339
-
1340
-	// gd ou gd2
1341
-	elseif ($process == 'gd1' or $process == 'gd2') {
1342
-		if (!function_exists('gd_info')) {
1343
-			spip_log("Librairie GD absente !", _LOG_ERREUR);
1344
-
1345
-			return;
1346
-		}
1347
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1348
-			spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1349
-
1350
-			return;
1351
-		}
1352
-		$destFormat = $format_sortie;
1353
-		if (!$destFormat) {
1354
-			spip_log("pas de format pour $image");
1355
-
1356
-			return;
1357
-		}
1358
-
1359
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1360
-		if (!function_exists($fonction_imagecreatefrom)) {
1361
-			return '';
1362
-		}
1363
-		$srcImage = @$fonction_imagecreatefrom($image);
1364
-		if (!$srcImage) {
1365
-			spip_log("echec gd1/gd2");
1366
-
1367
-			return;
1368
-		}
1369
-
1370
-		// Initialisation de l'image destination
1371
-		$destImage = null;
1372
-		if ($process == 'gd2' and $destFormat != "gif") {
1373
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1374
-		}
1375
-		if (!$destImage) {
1376
-			$destImage = ImageCreate($destWidth, $destHeight);
1377
-		}
1378
-
1379
-		// Recopie de l'image d'origine avec adaptation de la taille 
1380
-		$ok = false;
1381
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1382
-			if ($format == "gif") {
1383
-				// Si un GIF est transparent, 
1384
-				// fabriquer un PNG transparent  
1385
-				$transp = imagecolortransparent($srcImage);
1386
-				if ($transp > 0) {
1387
-					$destFormat = "png";
1388
-				}
1389
-			}
1390
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1391
-				// Conserver la transparence 
1392
-				if (function_exists("imageAntiAlias")) {
1393
-					imageAntiAlias($destImage, true);
1394
-				}
1395
-				@imagealphablending($destImage, false);
1396
-				@imagesavealpha($destImage, true);
1397
-			}
1398
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1399
-		}
1400
-		if (!$ok) {
1401
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1402
-		}
1403
-
1404
-		// Sauvegarde de l'image destination
1405
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1406
-		$valeurs['format_dest'] = $format = $destFormat;
1407
-		_image_gd_output($destImage, $valeurs);
1408
-
1409
-		if ($srcImage) {
1410
-			ImageDestroy($srcImage);
1411
-		}
1412
-		ImageDestroy($destImage);
1413
-	}
1414
-
1415
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1416
-		$size = array($destWidth, $destHeight);
1417
-	}
1418
-
1419
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1420
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1421
-	if ($size[0] < 1) {
1422
-		$size[0] = $destWidth;
1423
-	}
1424
-	if ($size[1] < 1) {
1425
-		$size[1] = $destHeight;
1426
-	}
1427
-
1428
-	$retour['width'] = $largeur = $size[0];
1429
-	$retour['height'] = $hauteur = $size[1];
1430
-
1431
-	$retour['fichier'] = $vignette;
1432
-	$retour['format'] = $format;
1433
-	$retour['date'] = @filemtime($vignette);
1434
-
1435
-	// renvoyer l'image
1436
-	return $retour;
1190
+    // ordre de preference des formats graphiques pour creer les vignettes
1191
+    // le premier format disponible, selon la methode demandee, est utilise
1192
+    $image = $valeurs['fichier'];
1193
+    $format = $valeurs['format_source'];
1194
+    $destdir = dirname($valeurs['fichier_dest']);
1195
+    $destfile = basename($valeurs['fichier_dest'], "." . $valeurs["format_dest"]);
1196
+
1197
+    $format_sortie = $valeurs['format_dest'];
1198
+
1199
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1200
+        $process = $GLOBALS['meta']['image_process'];
1201
+    }
1202
+
1203
+    // si le doc n'est pas une image dans un format accetpable, refuser
1204
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1205
+        return;
1206
+    }
1207
+    $destination = "$destdir/$destfile";
1208
+
1209
+    // calculer la taille
1210
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1211
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1212
+            list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight);
1213
+        }
1214
+    } elseif ($process == 'convert' or $process == 'imagick') {
1215
+        $destWidth = $maxWidth;
1216
+        $destHeight = $maxHeight;
1217
+    } else {
1218
+        spip_log("echec $process sur $image");
1219
+
1220
+        return;
1221
+    }
1222
+
1223
+    $vignette = '';
1224
+
1225
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1226
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1227
+        $vignette = $destination . '.' . $format;
1228
+        @copy($image, $vignette);
1229
+    }
1230
+
1231
+    elseif ($valeurs["format_source"] === 'svg') {
1232
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)){
1233
+            $format_sortie = 'svg';
1234
+            $vignette = $destination . "." . $format_sortie;
1235
+            $valeurs['fichier_dest'] = $vignette;
1236
+            _image_gd_output($svg, $valeurs);
1237
+        }
1238
+    }
1239
+
1240
+    // imagemagick en ligne de commande
1241
+    elseif ($process == 'convert') {
1242
+        if (!defined('_CONVERT_COMMAND')) {
1243
+            define('_CONVERT_COMMAND', 'convert');
1244
+        } // Securite : mes_options.php peut preciser le chemin absolu
1245
+        if (!defined('_RESIZE_COMMAND')) {
1246
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1247
+        }
1248
+        $vignette = $destination . "." . $format_sortie;
1249
+        $commande = str_replace(
1250
+            array('%x', '%y', '%src', '%dest'),
1251
+            array(
1252
+                $destWidth,
1253
+                $destHeight,
1254
+                escapeshellcmd($image),
1255
+                escapeshellcmd($vignette)
1256
+            ),
1257
+            _RESIZE_COMMAND);
1258
+        spip_log($commande);
1259
+        exec($commande);
1260
+        if (!@file_exists($vignette)) {
1261
+            spip_log("echec convert sur $vignette");
1262
+
1263
+            return;  // echec commande
1264
+        }
1265
+    }
1266
+
1267
+    // php5 imagemagick
1268
+    elseif ($process == 'imagick') {
1269
+        $vignette = "$destination." . $format_sortie;
1270
+
1271
+        if (!class_exists('Imagick')) {
1272
+            spip_log("Classe Imagick absente !", _LOG_ERREUR);
1273
+
1274
+            return;
1275
+        }
1276
+        $imagick = new Imagick();
1277
+        $imagick->readImage($image);
1278
+        $imagick->resizeImage($destWidth, $destHeight, Imagick::FILTER_LANCZOS,
1279
+            1);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1280
+        $imagick->writeImage($vignette);
1281
+
1282
+        if (!@file_exists($vignette)) {
1283
+            spip_log("echec imagick sur $vignette");
1284
+
1285
+            return;
1286
+        }
1287
+    }
1288
+
1289
+    // netpbm
1290
+    elseif ($process == "netpbm") {
1291
+        if (!defined('_PNMSCALE_COMMAND')) {
1292
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1293
+        } // Securite : mes_options.php peut preciser le chemin absolu
1294
+        if (_PNMSCALE_COMMAND == '') {
1295
+            return;
1296
+        }
1297
+        $vignette = $destination . "." . $format_sortie;
1298
+        $pnmtojpeg_command = str_replace("pnmscale", "pnmtojpeg", _PNMSCALE_COMMAND);
1299
+        if ($format == "jpg") {
1300
+
1301
+            $jpegtopnm_command = str_replace("pnmscale", "jpegtopnm", _PNMSCALE_COMMAND);
1302
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1303
+            if (!($s = @filesize($vignette))) {
1304
+                spip_unlink($vignette);
1305
+            }
1306
+            if (!@file_exists($vignette)) {
1307
+                spip_log("echec netpbm-jpg sur $vignette");
1308
+
1309
+                return;
1310
+            }
1311
+        } else {
1312
+            if ($format == "gif") {
1313
+                $giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
1314
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1315
+                if (!($s = @filesize($vignette))) {
1316
+                    spip_unlink($vignette);
1317
+                }
1318
+                if (!@file_exists($vignette)) {
1319
+                    spip_log("echec netpbm-gif sur $vignette");
1320
+
1321
+                    return;
1322
+                }
1323
+            } else {
1324
+                if ($format == "png") {
1325
+                    $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
1326
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1327
+                    if (!($s = @filesize($vignette))) {
1328
+                        spip_unlink($vignette);
1329
+                    }
1330
+                    if (!@file_exists($vignette)) {
1331
+                        spip_log("echec netpbm-png sur $vignette");
1332
+
1333
+                        return;
1334
+                    }
1335
+                }
1336
+            }
1337
+        }
1338
+    }
1339
+
1340
+    // gd ou gd2
1341
+    elseif ($process == 'gd1' or $process == 'gd2') {
1342
+        if (!function_exists('gd_info')) {
1343
+            spip_log("Librairie GD absente !", _LOG_ERREUR);
1344
+
1345
+            return;
1346
+        }
1347
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1348
+            spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
1349
+
1350
+            return;
1351
+        }
1352
+        $destFormat = $format_sortie;
1353
+        if (!$destFormat) {
1354
+            spip_log("pas de format pour $image");
1355
+
1356
+            return;
1357
+        }
1358
+
1359
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1360
+        if (!function_exists($fonction_imagecreatefrom)) {
1361
+            return '';
1362
+        }
1363
+        $srcImage = @$fonction_imagecreatefrom($image);
1364
+        if (!$srcImage) {
1365
+            spip_log("echec gd1/gd2");
1366
+
1367
+            return;
1368
+        }
1369
+
1370
+        // Initialisation de l'image destination
1371
+        $destImage = null;
1372
+        if ($process == 'gd2' and $destFormat != "gif") {
1373
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1374
+        }
1375
+        if (!$destImage) {
1376
+            $destImage = ImageCreate($destWidth, $destHeight);
1377
+        }
1378
+
1379
+        // Recopie de l'image d'origine avec adaptation de la taille 
1380
+        $ok = false;
1381
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1382
+            if ($format == "gif") {
1383
+                // Si un GIF est transparent, 
1384
+                // fabriquer un PNG transparent  
1385
+                $transp = imagecolortransparent($srcImage);
1386
+                if ($transp > 0) {
1387
+                    $destFormat = "png";
1388
+                }
1389
+            }
1390
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1391
+                // Conserver la transparence 
1392
+                if (function_exists("imageAntiAlias")) {
1393
+                    imageAntiAlias($destImage, true);
1394
+                }
1395
+                @imagealphablending($destImage, false);
1396
+                @imagesavealpha($destImage, true);
1397
+            }
1398
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1399
+        }
1400
+        if (!$ok) {
1401
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1402
+        }
1403
+
1404
+        // Sauvegarde de l'image destination
1405
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1406
+        $valeurs['format_dest'] = $format = $destFormat;
1407
+        _image_gd_output($destImage, $valeurs);
1408
+
1409
+        if ($srcImage) {
1410
+            ImageDestroy($srcImage);
1411
+        }
1412
+        ImageDestroy($destImage);
1413
+    }
1414
+
1415
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1416
+        $size = array($destWidth, $destHeight);
1417
+    }
1418
+
1419
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1420
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1421
+    if ($size[0] < 1) {
1422
+        $size[0] = $destWidth;
1423
+    }
1424
+    if ($size[1] < 1) {
1425
+        $size[1] = $destHeight;
1426
+    }
1427
+
1428
+    $retour['width'] = $largeur = $size[0];
1429
+    $retour['height'] = $hauteur = $size[1];
1430
+
1431
+    $retour['fichier'] = $vignette;
1432
+    $retour['format'] = $format;
1433
+    $retour['date'] = @filemtime($vignette);
1434
+
1435
+    // renvoyer l'image
1436
+    return $retour;
1437 1437
 }
1438 1438
 
1439 1439
 /**
@@ -1453,25 +1453,25 @@  discard block
 block discarded – undo
1453 1453
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1454 1454
  **/
1455 1455
 function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1456
-	$ratioWidth = $srcWidth / $maxWidth;
1457
-	$ratioHeight = $srcHeight / $maxHeight;
1458
-
1459
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1460
-		$destWidth = $srcWidth;
1461
-		$destHeight = $srcHeight;
1462
-	} elseif ($ratioWidth < $ratioHeight) {
1463
-		$destWidth = $srcWidth / $ratioHeight;
1464
-		$destHeight = $maxHeight;
1465
-	} else {
1466
-		$destWidth = $maxWidth;
1467
-		$destHeight = $srcHeight / $ratioWidth;
1468
-	}
1469
-
1470
-	return array(
1471
-		intval(round($destWidth)),
1472
-		intval(round($destHeight)),
1473
-		max($ratioWidth, $ratioHeight)
1474
-	);
1456
+    $ratioWidth = $srcWidth / $maxWidth;
1457
+    $ratioHeight = $srcHeight / $maxHeight;
1458
+
1459
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1460
+        $destWidth = $srcWidth;
1461
+        $destHeight = $srcHeight;
1462
+    } elseif ($ratioWidth < $ratioHeight) {
1463
+        $destWidth = $srcWidth / $ratioHeight;
1464
+        $destHeight = $maxHeight;
1465
+    } else {
1466
+        $destWidth = $maxWidth;
1467
+        $destHeight = $srcHeight / $ratioWidth;
1468
+    }
1469
+
1470
+    return array(
1471
+        intval(round($destWidth)),
1472
+        intval(round($destHeight)),
1473
+        max($ratioWidth, $ratioHeight)
1474
+    );
1475 1475
 }
1476 1476
 
1477 1477
 /**
@@ -1491,25 +1491,25 @@  discard block
 block discarded – undo
1491 1491
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1492 1492
  **/
1493 1493
 function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) {
1494
-	$ratioWidth = $srcWidth / $maxWidth;
1495
-	$ratioHeight = $srcHeight / $maxHeight;
1496
-
1497
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1498
-		$destWidth = $srcWidth;
1499
-		$destHeight = $srcHeight;
1500
-	} elseif ($ratioWidth > $ratioHeight) {
1501
-		$destWidth = $srcWidth / $ratioHeight;
1502
-		$destHeight = $maxHeight;
1503
-	} else {
1504
-		$destWidth = $maxWidth;
1505
-		$destHeight = $srcHeight / $ratioWidth;
1506
-	}
1507
-
1508
-	return array(
1509
-		intval(round($destWidth)),
1510
-		intval(round($destHeight)),
1511
-		min($ratioWidth, $ratioHeight)
1512
-	);
1494
+    $ratioWidth = $srcWidth / $maxWidth;
1495
+    $ratioHeight = $srcHeight / $maxHeight;
1496
+
1497
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1498
+        $destWidth = $srcWidth;
1499
+        $destHeight = $srcHeight;
1500
+    } elseif ($ratioWidth > $ratioHeight) {
1501
+        $destWidth = $srcWidth / $ratioHeight;
1502
+        $destHeight = $maxHeight;
1503
+    } else {
1504
+        $destWidth = $maxWidth;
1505
+        $destHeight = $srcHeight / $ratioWidth;
1506
+    }
1507
+
1508
+    return array(
1509
+        intval(round($destWidth)),
1510
+        intval(round($destHeight)),
1511
+        min($ratioWidth, $ratioHeight)
1512
+    );
1513 1513
 }
1514 1514
 
1515 1515
 
@@ -1522,12 +1522,12 @@  discard block
 block discarded – undo
1522 1522
  * @return string
1523 1523
  */
1524 1524
 function process_image_svg_identite($image) {
1525
-	if ($image['creer']) {
1526
-		$source = $image['fichier'];
1527
-		_image_gd_output($source, $image);
1528
-	}
1525
+    if ($image['creer']) {
1526
+        $source = $image['fichier'];
1527
+        _image_gd_output($source, $image);
1528
+    }
1529 1529
 
1530
-	return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1530
+    return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1531 1531
 }
1532 1532
 
1533 1533
 
@@ -1560,104 +1560,104 @@  discard block
 block discarded – undo
1560 1560
  *     Code HTML de la balise img produite
1561 1561
  **/
1562 1562
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1563
-	$image = false;
1564
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1565
-		$process = $GLOBALS['meta']['image_process'];
1566
-	}
1567
-	# determiner le format de sortie
1568
-	$format_sortie = false; // le choix par defaut sera bon
1569
-	if ($process == "netpbm") {
1570
-		$format_sortie = "jpg";
1571
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1572
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1573
-		// on verifie que l'extension choisie est bonne (en principe oui)
1574
-		$gd_formats = formats_image_acceptables(true);
1575
-		if (is_array($image)
1576
-			and (!in_array($image['format_dest'], $gd_formats)
1577
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1578
-			)
1579
-		) {
1580
-			if ($image['format_source'] == 'jpg') {
1581
-				$formats_sortie = array('jpg', 'png', 'gif');
1582
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1583
-			{
1584
-				$formats_sortie = array('png', 'jpg', 'gif');
1585
-			}
1586
-			// Choisir le format destination
1587
-			// - on sauve de preference en JPEG (meilleure compression)
1588
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1589
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1590
-			# pas *ecrire*
1591
-			$format_sortie = "";
1592
-			foreach ($formats_sortie as $fmt) {
1593
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1594
-					$format_sortie = $fmt;
1595
-					break;
1596
-				}
1597
-			}
1598
-			$image = false;
1599
-		}
1600
-	}
1601
-
1602
-	if (!is_array($image)) {
1603
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1604
-	}
1605
-
1606
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1607
-		spip_log("image_reduire_src:pas de version locale de $img");
1608
-		// on peut resizer en mode html si on dispose des elements
1609
-		if ($srcw = extraire_attribut($img, 'width')
1610
-			and $srch = extraire_attribut($img, 'height')
1611
-		) {
1612
-			list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1613
-
1614
-			return _image_tag_changer_taille($img, $w, $h);
1615
-		}
1616
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1617
-		// sous la forme style='max-width: NNpx;'
1618
-		return inserer_attribut($img, 'style',
1619
-			"max-width: ${taille}px; max-height: ${taille_y}px");
1620
-	}
1621
-
1622
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1623
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1624
-		if ($image['creer']) {
1625
-			@copy($image['fichier'], $image['fichier_dest']);
1626
-		}
1627
-
1628
-		return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1629
-	}
1630
-
1631
-	if ($image['creer'] == false && !$force) {
1632
-		return _image_ecrire_tag($image,
1633
-			array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
1634
-	}
1635
-
1636
-	if (in_array($image["format_source"], _image_extensions_acceptees_en_entree())) {
1637
-		$destWidth = $image['largeur_dest'];
1638
-		$destHeight = $image['hauteur_dest'];
1639
-		$logo = $image['fichier'];
1640
-		$date = $image["date_src"];
1641
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1642
-
1643
-		if ($preview && $preview['fichier']) {
1644
-			$logo = $preview['fichier'];
1645
-			$destWidth = $preview['width'];
1646
-			$destHeight = $preview['height'];
1647
-			$date = $preview['date'];
1648
-		}
1649
-		// dans l'espace prive mettre un timestamp sur l'adresse 
1650
-		// de l'image, de facon a tromper le cache du navigateur
1651
-		// quand on fait supprimer/reuploader un logo
1652
-		// (pas de filemtime si SAFE MODE)
1653
-		$date = test_espace_prive() ? ('?' . $date) : '';
1654
-
1655
-		return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1656
-	}
1657
-	else {
1658
-		# BMP, tiff ... les redacteurs osent tout!
1659
-		return $img;
1660
-	}
1563
+    $image = false;
1564
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1565
+        $process = $GLOBALS['meta']['image_process'];
1566
+    }
1567
+    # determiner le format de sortie
1568
+    $format_sortie = false; // le choix par defaut sera bon
1569
+    if ($process == "netpbm") {
1570
+        $format_sortie = "jpg";
1571
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1572
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1573
+        // on verifie que l'extension choisie est bonne (en principe oui)
1574
+        $gd_formats = formats_image_acceptables(true);
1575
+        if (is_array($image)
1576
+            and (!in_array($image['format_dest'], $gd_formats)
1577
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1578
+            )
1579
+        ) {
1580
+            if ($image['format_source'] == 'jpg') {
1581
+                $formats_sortie = array('jpg', 'png', 'gif');
1582
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1583
+            {
1584
+                $formats_sortie = array('png', 'jpg', 'gif');
1585
+            }
1586
+            // Choisir le format destination
1587
+            // - on sauve de preference en JPEG (meilleure compression)
1588
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1589
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1590
+            # pas *ecrire*
1591
+            $format_sortie = "";
1592
+            foreach ($formats_sortie as $fmt) {
1593
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1594
+                    $format_sortie = $fmt;
1595
+                    break;
1596
+                }
1597
+            }
1598
+            $image = false;
1599
+        }
1600
+    }
1601
+
1602
+    if (!is_array($image)) {
1603
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1604
+    }
1605
+
1606
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1607
+        spip_log("image_reduire_src:pas de version locale de $img");
1608
+        // on peut resizer en mode html si on dispose des elements
1609
+        if ($srcw = extraire_attribut($img, 'width')
1610
+            and $srch = extraire_attribut($img, 'height')
1611
+        ) {
1612
+            list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y);
1613
+
1614
+            return _image_tag_changer_taille($img, $w, $h);
1615
+        }
1616
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1617
+        // sous la forme style='max-width: NNpx;'
1618
+        return inserer_attribut($img, 'style',
1619
+            "max-width: ${taille}px; max-height: ${taille_y}px");
1620
+    }
1621
+
1622
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1623
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1624
+        if ($image['creer']) {
1625
+            @copy($image['fichier'], $image['fichier_dest']);
1626
+        }
1627
+
1628
+        return _image_ecrire_tag($image, array('src' => $image['fichier_dest']));
1629
+    }
1630
+
1631
+    if ($image['creer'] == false && !$force) {
1632
+        return _image_ecrire_tag($image,
1633
+            array('src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']));
1634
+    }
1635
+
1636
+    if (in_array($image["format_source"], _image_extensions_acceptees_en_entree())) {
1637
+        $destWidth = $image['largeur_dest'];
1638
+        $destHeight = $image['hauteur_dest'];
1639
+        $logo = $image['fichier'];
1640
+        $date = $image["date_src"];
1641
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1642
+
1643
+        if ($preview && $preview['fichier']) {
1644
+            $logo = $preview['fichier'];
1645
+            $destWidth = $preview['width'];
1646
+            $destHeight = $preview['height'];
1647
+            $date = $preview['date'];
1648
+        }
1649
+        // dans l'espace prive mettre un timestamp sur l'adresse 
1650
+        // de l'image, de facon a tromper le cache du navigateur
1651
+        // quand on fait supprimer/reuploader un logo
1652
+        // (pas de filemtime si SAFE MODE)
1653
+        $date = test_espace_prive() ? ('?' . $date) : '';
1654
+
1655
+        return _image_ecrire_tag($image, array('src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight));
1656
+    }
1657
+    else {
1658
+        # BMP, tiff ... les redacteurs osent tout!
1659
+        return $img;
1660
+    }
1661 1661
 }
1662 1662
 
1663 1663
 /**
@@ -1672,144 +1672,144 @@  discard block
 block discarded – undo
1672 1672
  */
1673 1673
 class phpthumb_functions {
1674 1674
 
1675
-	/**
1676
-	 * Retourne la couleur d'un pixel dans une image
1677
-	 *
1678
-	 * @param ressource $img
1679
-	 * @param int $x
1680
-	 * @param int $y
1681
-	 * @return array|bool
1682
-	 */
1683
-	public static function GetPixelColor(&$img, $x, $y) {
1684
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1685
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1686
-		}
1687
-		return false;
1688
-	}
1689
-
1690
-	/**
1691
-	 * Retourne un nombre dans une représentation en Little Endian
1692
-	 *
1693
-	 * @param int $number
1694
-	 * @param int $minbytes
1695
-	 * @return string
1696
-	 */
1697
-	public static function LittleEndian2String($number, $minbytes = 1) {
1698
-		$intstring = '';
1699
-		while ($number > 0) {
1700
-			$intstring = $intstring . chr($number & 255);
1701
-			$number >>= 8;
1702
-		}
1703
-
1704
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1705
-	}
1706
-
1707
-	/**
1708
-	 * Transforme une ressource GD en image au format ICO
1709
-	 *
1710
-	 * @param array $gd_image_array
1711
-	 *     Tableau de ressources d'images GD
1712
-	 * @return string
1713
-	 *     Image au format ICO
1714
-	 */
1715
-	public static function GD2ICOstring(&$gd_image_array) {
1716
-		foreach ($gd_image_array as $key => $gd_image) {
1717
-
1718
-			$ImageWidths[$key] = ImageSX($gd_image);
1719
-			$ImageHeights[$key] = ImageSY($gd_image);
1720
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1721
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1722
-
1723
-			$icXOR[$key] = '';
1724
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1725
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1726
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1727
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1728
-					$r = $argb['red'];
1729
-					$g = $argb['green'];
1730
-					$b = $argb['blue'];
1731
-
1732
-					if ($bpp[$key] == 32) {
1733
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1734
-					} elseif ($bpp[$key] == 24) {
1735
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1736
-					}
1737
-
1738
-					if ($a < 128) {
1739
-						@$icANDmask[$key][$y] .= '1';
1740
-					} else {
1741
-						@$icANDmask[$key][$y] .= '0';
1742
-					}
1743
-				}
1744
-				// mask bits are 32-bit aligned per scanline
1745
-				while (strlen($icANDmask[$key][$y]) % 32) {
1746
-					$icANDmask[$key][$y] .= '0';
1747
-				}
1748
-			}
1749
-			$icAND[$key] = '';
1750
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1751
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1752
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1753
-				}
1754
-			}
1755
-
1756
-		}
1757
-
1758
-		foreach ($gd_image_array as $key => $gd_image) {
1759
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1760
-
1761
-			// BITMAPINFOHEADER - 40 bytes
1762
-			$BitmapInfoHeader[$key] = '';
1763
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1764
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1765
-			// The biHeight member specifies the combined
1766
-			// height of the XOR and AND masks.
1767
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1768
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1769
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1770
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1771
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1772
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1773
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1774
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1775
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1776
-		}
1777
-
1778
-
1779
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1780
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1781
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1782
-
1783
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1784
-		foreach ($gd_image_array as $key => $gd_image) {
1785
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1786
-
1787
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1788
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1789
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1790
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1791
-
1792
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1793
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1794
-
1795
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1796
-			$icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1797
-				4);     // dwBytesInRes;	// How many bytes in this resource?
1798
-
1799
-			$icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1800
-				4);    // dwImageOffset;   // Where in the file is this image?
1801
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1802
-			$dwImageOffset += strlen($icXOR[$key]);
1803
-			$dwImageOffset += strlen($icAND[$key]);
1804
-		}
1805
-
1806
-		foreach ($gd_image_array as $key => $gd_image) {
1807
-			$icondata .= $BitmapInfoHeader[$key];
1808
-			$icondata .= $icXOR[$key];
1809
-			$icondata .= $icAND[$key];
1810
-		}
1811
-
1812
-		return $icondata;
1813
-	}
1675
+    /**
1676
+     * Retourne la couleur d'un pixel dans une image
1677
+     *
1678
+     * @param ressource $img
1679
+     * @param int $x
1680
+     * @param int $y
1681
+     * @return array|bool
1682
+     */
1683
+    public static function GetPixelColor(&$img, $x, $y) {
1684
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1685
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1686
+        }
1687
+        return false;
1688
+    }
1689
+
1690
+    /**
1691
+     * Retourne un nombre dans une représentation en Little Endian
1692
+     *
1693
+     * @param int $number
1694
+     * @param int $minbytes
1695
+     * @return string
1696
+     */
1697
+    public static function LittleEndian2String($number, $minbytes = 1) {
1698
+        $intstring = '';
1699
+        while ($number > 0) {
1700
+            $intstring = $intstring . chr($number & 255);
1701
+            $number >>= 8;
1702
+        }
1703
+
1704
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1705
+    }
1706
+
1707
+    /**
1708
+     * Transforme une ressource GD en image au format ICO
1709
+     *
1710
+     * @param array $gd_image_array
1711
+     *     Tableau de ressources d'images GD
1712
+     * @return string
1713
+     *     Image au format ICO
1714
+     */
1715
+    public static function GD2ICOstring(&$gd_image_array) {
1716
+        foreach ($gd_image_array as $key => $gd_image) {
1717
+
1718
+            $ImageWidths[$key] = ImageSX($gd_image);
1719
+            $ImageHeights[$key] = ImageSY($gd_image);
1720
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1721
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1722
+
1723
+            $icXOR[$key] = '';
1724
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1725
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1726
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1727
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1728
+                    $r = $argb['red'];
1729
+                    $g = $argb['green'];
1730
+                    $b = $argb['blue'];
1731
+
1732
+                    if ($bpp[$key] == 32) {
1733
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1734
+                    } elseif ($bpp[$key] == 24) {
1735
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1736
+                    }
1737
+
1738
+                    if ($a < 128) {
1739
+                        @$icANDmask[$key][$y] .= '1';
1740
+                    } else {
1741
+                        @$icANDmask[$key][$y] .= '0';
1742
+                    }
1743
+                }
1744
+                // mask bits are 32-bit aligned per scanline
1745
+                while (strlen($icANDmask[$key][$y]) % 32) {
1746
+                    $icANDmask[$key][$y] .= '0';
1747
+                }
1748
+            }
1749
+            $icAND[$key] = '';
1750
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1751
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1752
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1753
+                }
1754
+            }
1755
+
1756
+        }
1757
+
1758
+        foreach ($gd_image_array as $key => $gd_image) {
1759
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1760
+
1761
+            // BITMAPINFOHEADER - 40 bytes
1762
+            $BitmapInfoHeader[$key] = '';
1763
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1764
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1765
+            // The biHeight member specifies the combined
1766
+            // height of the XOR and AND masks.
1767
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1768
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1769
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1770
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1771
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1772
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1773
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1774
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1775
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1776
+        }
1777
+
1778
+
1779
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1780
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1781
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1782
+
1783
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1784
+        foreach ($gd_image_array as $key => $gd_image) {
1785
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1786
+
1787
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1788
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1789
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1790
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1791
+
1792
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1793
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1794
+
1795
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1796
+            $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes,
1797
+                4);     // dwBytesInRes;	// How many bytes in this resource?
1798
+
1799
+            $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset,
1800
+                4);    // dwImageOffset;   // Where in the file is this image?
1801
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1802
+            $dwImageOffset += strlen($icXOR[$key]);
1803
+            $dwImageOffset += strlen($icAND[$key]);
1804
+        }
1805
+
1806
+        foreach ($gd_image_array as $key => $gd_image) {
1807
+            $icondata .= $BitmapInfoHeader[$key];
1808
+            $icondata .= $icXOR[$key];
1809
+            $icondata .= $icAND[$key];
1810
+        }
1811
+
1812
+        return $icondata;
1813
+    }
1814 1814
 
1815 1815
 }
Please login to merge, or discard this patch.