Completed
Push — master ( f7786b...3465fc )
by cam
01:27
created
ecrire/inc/filtres_images_lib_mini.php 3 patches
Indentation   +1329 added lines, -1329 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$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 = [];
74
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
75
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
76
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
77
-
78
-	return $retour;
67
+    $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 = [];
74
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
75
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
76
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
77
+
78
+    return $retour;
79 79
 }
80 80
 
81 81
 
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
  *     Le code de la couleur en hexadécimal.
93 93
  */
94 94
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
95
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
96
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
95
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
96
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
97 97
 }
98 98
 
99 99
 /**
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
106 106
  */
107 107
 function _couleur_hex_to_hsl($couleur) {
108
-	$rgb = _couleur_hex_to_dec($couleur);
109
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
108
+    $rgb = _couleur_hex_to_dec($couleur);
109
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
110 110
 }
111 111
 
112 112
 /**
@@ -121,59 +121,59 @@  discard block
 block discarded – undo
121 121
  * @return array
122 122
  */
123 123
 function _couleur_rgb_to_hsl($R, $G, $B) {
124
-	$H = null;
125
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
126
-	$var_G = ($G / 255);
127
-	$var_B = ($B / 255);
128
-
129
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
132
-
133
-	$L = ($var_Max + $var_Min) / 2;
134
-
135
-	if ($del_Max == 0) {
136
-		//This is a gray, no chroma...
137
-		$H = 0; //HSL results = 0 ÷ 1
138
-		$S = 0;
139
-	} else {
140
-		// Chromatic data...
141
-		if ($L < 0.5) {
142
-			$S = $del_Max / ($var_Max + $var_Min);
143
-		} else {
144
-			$S = $del_Max / (2 - $var_Max - $var_Min);
145
-		}
146
-
147
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
148
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
149
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
150
-
151
-		if ($var_R == $var_Max) {
152
-			$H = $del_B - $del_G;
153
-		} else {
154
-			if ($var_G == $var_Max) {
155
-				$H = (1 / 3) + $del_R - $del_B;
156
-			} else {
157
-				if ($var_B == $var_Max) {
158
-					$H = (2 / 3) + $del_G - $del_R;
159
-				}
160
-			}
161
-		}
162
-
163
-		if ($H < 0) {
164
-			$H += 1;
165
-		}
166
-		if ($H > 1) {
167
-			$H -= 1;
168
-		}
169
-	}
170
-
171
-	$ret = [];
172
-	$ret['h'] = $H;
173
-	$ret['s'] = $S;
174
-	$ret['l'] = $L;
175
-
176
-	return $ret;
124
+    $H = null;
125
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
126
+    $var_G = ($G / 255);
127
+    $var_B = ($B / 255);
128
+
129
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
132
+
133
+    $L = ($var_Max + $var_Min) / 2;
134
+
135
+    if ($del_Max == 0) {
136
+        //This is a gray, no chroma...
137
+        $H = 0; //HSL results = 0 ÷ 1
138
+        $S = 0;
139
+    } else {
140
+        // Chromatic data...
141
+        if ($L < 0.5) {
142
+            $S = $del_Max / ($var_Max + $var_Min);
143
+        } else {
144
+            $S = $del_Max / (2 - $var_Max - $var_Min);
145
+        }
146
+
147
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
148
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
149
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
150
+
151
+        if ($var_R == $var_Max) {
152
+            $H = $del_B - $del_G;
153
+        } else {
154
+            if ($var_G == $var_Max) {
155
+                $H = (1 / 3) + $del_R - $del_B;
156
+            } else {
157
+                if ($var_B == $var_Max) {
158
+                    $H = (2 / 3) + $del_G - $del_R;
159
+                }
160
+            }
161
+        }
162
+
163
+        if ($H < 0) {
164
+            $H += 1;
165
+        }
166
+        if ($H > 1) {
167
+            $H -= 1;
168
+        }
169
+    }
170
+
171
+    $ret = [];
172
+    $ret['h'] = $H;
173
+    $ret['s'] = $S;
174
+    $ret['l'] = $L;
175
+
176
+    return $ret;
177 177
 }
178 178
 
179 179
 
@@ -189,52 +189,52 @@  discard block
 block discarded – undo
189 189
  * @return array
190 190
  */
191 191
 function _couleur_hsl_to_rgb($H, $S, $L) {
192
-	// helper
193
-	$hue_2_rgb = function ($v1, $v2, $vH) {
194
-		if ($vH < 0) {
195
-			$vH += 1;
196
-		}
197
-		if ($vH > 1) {
198
-			$vH -= 1;
199
-		}
200
-		if ((6 * $vH) < 1) {
201
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
202
-		}
203
-		if ((2 * $vH) < 1) {
204
-			return ($v2);
205
-		}
206
-		if ((3 * $vH) < 2) {
207
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
208
-		}
209
-
210
-		return ($v1);
211
-	};
212
-
213
-	if ($S == 0) {
214
-		// HSV values = 0 -> 1
215
-		$R = $L * 255;
216
-		$G = $L * 255;
217
-		$B = $L * 255;
218
-	} else {
219
-		if ($L < 0.5) {
220
-			$var_2 = $L * (1 + $S);
221
-		} else {
222
-			$var_2 = ($L + $S) - ($S * $L);
223
-		}
224
-
225
-		$var_1 = 2 * $L - $var_2;
226
-
227
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
228
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
229
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
230
-	}
231
-
232
-	$ret = [];
233
-	$ret['r'] = floor($R);
234
-	$ret['g'] = floor($G);
235
-	$ret['b'] = floor($B);
236
-
237
-	return $ret;
192
+    // helper
193
+    $hue_2_rgb = function ($v1, $v2, $vH) {
194
+        if ($vH < 0) {
195
+            $vH += 1;
196
+        }
197
+        if ($vH > 1) {
198
+            $vH -= 1;
199
+        }
200
+        if ((6 * $vH) < 1) {
201
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
202
+        }
203
+        if ((2 * $vH) < 1) {
204
+            return ($v2);
205
+        }
206
+        if ((3 * $vH) < 2) {
207
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
208
+        }
209
+
210
+        return ($v1);
211
+    };
212
+
213
+    if ($S == 0) {
214
+        // HSV values = 0 -> 1
215
+        $R = $L * 255;
216
+        $G = $L * 255;
217
+        $B = $L * 255;
218
+    } else {
219
+        if ($L < 0.5) {
220
+            $var_2 = $L * (1 + $S);
221
+        } else {
222
+            $var_2 = ($L + $S) - ($S * $L);
223
+        }
224
+
225
+        $var_1 = 2 * $L - $var_2;
226
+
227
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
228
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
229
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
230
+    }
231
+
232
+    $ret = [];
233
+    $ret['r'] = floor($R);
234
+    $ret['g'] = floor($G);
235
+    $ret['b'] = floor($B);
236
+
237
+    return $ret;
238 238
 }
239 239
 
240 240
 /**
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
  *     true si il faut supprimer le fichier temporaire ; false sinon.
253 253
  */
254 254
 function statut_effacer_images_temporaires($stat) {
255
-	static $statut = false; // par defaut on grave toute les images
256
-	if ($stat === 'get') {
257
-		return $statut;
258
-	}
259
-	$statut = $stat ? true : false;
255
+    static $statut = false; // par defaut on grave toute les images
256
+    if ($stat === 'get') {
257
+        return $statut;
258
+    }
259
+    $statut = $stat ? true : false;
260 260
 }
261 261
 
262 262
 
@@ -309,247 +309,247 @@  discard block
 block discarded – undo
309 309
  *     - array : tableau décrivant de l'image
310 310
  */
311 311
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
312
-	$ret = [];
313
-	$f = null;
314
-	static $images_recalcul = [];
315
-	if (strlen($img) == 0) {
316
-		return false;
317
-	}
318
-
319
-	$source = trim(extraire_attribut($img, 'src') ?? '');
320
-	if (strlen($source) < 1) {
321
-		$source = $img;
322
-		$img = "<img src='$source' />";
323
-	} elseif (
324
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
326
-		and in_array($extension, _image_extensions_acceptees_en_entree())
327
-	) {
328
-		# gerer img src="data:....base64"
329
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
330
-		if (!file_exists($local)) {
331
-			ecrire_fichier($local, base64_decode($regs[2]));
332
-		}
333
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
334
-			$sanitizer($local);
335
-		}
336
-		$source = $local;
337
-		$img = inserer_attribut($img, 'src', $source);
338
-		# eviter les mauvaises surprises lors de conversions de format
339
-		$img = inserer_attribut($img, 'width', '');
340
-		$img = inserer_attribut($img, 'height', '');
341
-	}
342
-
343
-	// les protocoles web prennent au moins 3 lettres
344
-	if (tester_url_absolue($source)) {
345
-		include_spip('inc/distant');
346
-		$fichier = _DIR_RACINE . copie_locale($source);
347
-		if (!$fichier) {
348
-			return '';
349
-		}
350
-		if (
351
-			$extension = _image_trouver_extension($fichier)
352
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
353
-		) {
354
-			$sanitizer($fichier);
355
-		}
356
-	} else {
357
-		// enlever le timestamp eventuel
358
-		if (strpos($source, '?') !== false) {
359
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
360
-		}
361
-		if (
362
-			strpos($source, '?') !== false
363
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
364
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
365
-		) {
366
-			$source = $f;
367
-		}
368
-		$fichier = $source;
369
-	}
370
-
371
-	$terminaison_dest = '';
372
-	if ($terminaison = _image_trouver_extension($fichier)) {
373
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
374
-	}
375
-
376
-	if (
377
-		$forcer_format !== false
378
-		// 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
379
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
380
-	) {
381
-		$terminaison_dest = $forcer_format;
382
-	}
383
-
384
-	if (!$terminaison_dest) {
385
-		return false;
386
-	}
387
-
388
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
389
-	$fichier_dest = $nom_fichier;
390
-	if (
391
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
392
-		or @file_exists($f = $fichier)
393
-	) {
394
-		// on passe la balise img a taille image qui exraira les attributs si possible
395
-		// au lieu de faire un acces disque sur le fichier
396
-		[$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
397
-		$date_src = @filemtime($f);
398
-	} elseif (
399
-		@file_exists($f = "$fichier.src")
400
-		and lire_fichier($f, $valeurs)
401
-		and $valeurs = unserialize($valeurs)
402
-		and isset($valeurs['hauteur_dest'])
403
-		and isset($valeurs['largeur_dest'])
404
-	) {
405
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
406
-		$ret['largeur'] = $valeurs['largeur_dest'];
407
-		$date_src = $valeurs['date'];
408
-	} // pas de fichier source par la
409
-	else {
410
-		return false;
411
-	}
412
-
413
-	// pas de taille mesurable ?
414
-	if (!$ret['hauteur']
415
-		or !($ret['hauteur'] = intval(round($ret['hauteur'])))
416
-		or !$ret['largeur']
417
-		or !($ret['largeur'] = intval(round($ret['largeur'])))
418
-	) {
419
-		return false;
420
-	}
421
-
422
-	// les images calculees dependent du chemin du fichier source
423
-	// 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
424
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
425
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
426
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
427
-	// alors que ca concerne peu de site au final
428
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
429
-	$identifiant = $fichier;
430
-
431
-	// cas general :
432
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
433
-	// cas particulier de reduire :
434
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
435
-	$cache = 'cache-gd2';
436
-	if (substr($effet, 0, 7) == 'reduire') {
437
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
438
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
439
-		$ret['largeur_dest'] = $destWidth;
440
-		$ret['hauteur_dest'] = $destHeight;
441
-		$effet = "L{$destWidth}xH$destHeight";
442
-		$cache = 'cache-vignettes';
443
-		$fichier_dest = basename($fichier_dest);
444
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
445
-			// on garde la terminaison initiale car image simplement copiee
446
-			// et on postfixe son nom avec un md5 du path
447
-			$terminaison_dest = $terminaison;
448
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
449
-		} else {
450
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
451
-		}
452
-		$cache = sous_repertoire(_DIR_VAR, $cache);
453
-		$cache = sous_repertoire($cache, $effet);
454
-	} else {
455
-		$fichier_dest = md5("$identifiant-$effet");
456
-		$cache = sous_repertoire(_DIR_VAR, $cache);
457
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
458
-		$fichier_dest = substr($fichier_dest, 2);
459
-	}
460
-
461
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
462
-
463
-	$GLOBALS['images_calculees'][] = $fichier_dest;
464
-
465
-	$creer = true;
466
-	// si recalcul des images demande, recalculer chaque image une fois
467
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
468
-		$images_recalcul[$fichier_dest] = true;
469
-	} else {
470
-		if (@file_exists($f = $fichier_dest)) {
471
-			if (filemtime($f) >= $date_src) {
472
-				$creer = false;
473
-			}
474
-		} else {
475
-			if (
476
-				@file_exists($f = "$fichier_dest.src")
477
-				and lire_fichier($f, $valeurs)
478
-				and $valeurs = unserialize($valeurs)
479
-				and $valeurs['date'] >= $date_src
480
-			) {
481
-				$creer = false;
482
-			}
483
-		}
484
-	}
485
-	if ($creer) {
486
-		if (!@file_exists($fichier)) {
487
-			if (!@file_exists("$fichier.src")) {
488
-				spip_log("Image absente : $fichier");
489
-
490
-				return false;
491
-			}
492
-			# on reconstruit l'image source absente a partir de la chaine des .src
493
-			reconstruire_image_intermediaire($fichier);
494
-		}
495
-	}
496
-
497
-	if ($creer) {
498
-		spip_log(
499
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
500
-			'images' . _LOG_DEBUG
501
-		);
502
-	}
503
-
504
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
505
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
506
-	$ret['fichier'] = $fichier;
507
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
508
-	$ret['fichier_dest'] = $fichier_dest;
509
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
510
-	$ret['format_dest'] = $terminaison_dest;
511
-	$ret['date_src'] = $date_src;
512
-	$ret['creer'] = $creer;
513
-	$ret['class'] = extraire_attribut($img, 'class');
514
-	$ret['alt'] = extraire_attribut($img, 'alt');
515
-	$ret['style'] = extraire_attribut($img, 'style');
516
-	$ret['tag'] = $img;
517
-	if ($fonction_creation) {
518
-		$ret['reconstruction'] = $fonction_creation;
519
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
520
-		# cas de image_reduire qui finalement ne reduit pas l'image source
521
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
522
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
523
-	}
524
-
525
-	$ret = pipeline('image_preparer_filtre', [
526
-			'args' => [
527
-				'img' => $img,
528
-				'effet' => $effet,
529
-				'forcer_format' => $forcer_format,
530
-				'fonction_creation' => $fonction_creation,
531
-				'find_in_path' => $find_in_path,
532
-			],
533
-			'data' => $ret
534
-		]);
535
-
536
-	// une globale pour le debug en cas de crash memoire
537
-	$GLOBALS['derniere_image_calculee'] = $ret;
538
-
539
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
540
-	if ($term_fonction === 'svg') {
541
-		if ($creer and !$support_svg) {
542
-			process_image_svg_identite($ret);
543
-			$ret['creer'] = false;
544
-		}
545
-	}
546
-	else {
547
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
548
-			return false;
549
-		}
550
-	}
551
-
552
-	return $ret;
312
+    $ret = [];
313
+    $f = null;
314
+    static $images_recalcul = [];
315
+    if (strlen($img) == 0) {
316
+        return false;
317
+    }
318
+
319
+    $source = trim(extraire_attribut($img, 'src') ?? '');
320
+    if (strlen($source) < 1) {
321
+        $source = $img;
322
+        $img = "<img src='$source' />";
323
+    } elseif (
324
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
326
+        and in_array($extension, _image_extensions_acceptees_en_entree())
327
+    ) {
328
+        # gerer img src="data:....base64"
329
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
330
+        if (!file_exists($local)) {
331
+            ecrire_fichier($local, base64_decode($regs[2]));
332
+        }
333
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
334
+            $sanitizer($local);
335
+        }
336
+        $source = $local;
337
+        $img = inserer_attribut($img, 'src', $source);
338
+        # eviter les mauvaises surprises lors de conversions de format
339
+        $img = inserer_attribut($img, 'width', '');
340
+        $img = inserer_attribut($img, 'height', '');
341
+    }
342
+
343
+    // les protocoles web prennent au moins 3 lettres
344
+    if (tester_url_absolue($source)) {
345
+        include_spip('inc/distant');
346
+        $fichier = _DIR_RACINE . copie_locale($source);
347
+        if (!$fichier) {
348
+            return '';
349
+        }
350
+        if (
351
+            $extension = _image_trouver_extension($fichier)
352
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
353
+        ) {
354
+            $sanitizer($fichier);
355
+        }
356
+    } else {
357
+        // enlever le timestamp eventuel
358
+        if (strpos($source, '?') !== false) {
359
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
360
+        }
361
+        if (
362
+            strpos($source, '?') !== false
363
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
364
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
365
+        ) {
366
+            $source = $f;
367
+        }
368
+        $fichier = $source;
369
+    }
370
+
371
+    $terminaison_dest = '';
372
+    if ($terminaison = _image_trouver_extension($fichier)) {
373
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
374
+    }
375
+
376
+    if (
377
+        $forcer_format !== false
378
+        // 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
379
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
380
+    ) {
381
+        $terminaison_dest = $forcer_format;
382
+    }
383
+
384
+    if (!$terminaison_dest) {
385
+        return false;
386
+    }
387
+
388
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
389
+    $fichier_dest = $nom_fichier;
390
+    if (
391
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
392
+        or @file_exists($f = $fichier)
393
+    ) {
394
+        // on passe la balise img a taille image qui exraira les attributs si possible
395
+        // au lieu de faire un acces disque sur le fichier
396
+        [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
397
+        $date_src = @filemtime($f);
398
+    } elseif (
399
+        @file_exists($f = "$fichier.src")
400
+        and lire_fichier($f, $valeurs)
401
+        and $valeurs = unserialize($valeurs)
402
+        and isset($valeurs['hauteur_dest'])
403
+        and isset($valeurs['largeur_dest'])
404
+    ) {
405
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
406
+        $ret['largeur'] = $valeurs['largeur_dest'];
407
+        $date_src = $valeurs['date'];
408
+    } // pas de fichier source par la
409
+    else {
410
+        return false;
411
+    }
412
+
413
+    // pas de taille mesurable ?
414
+    if (!$ret['hauteur']
415
+        or !($ret['hauteur'] = intval(round($ret['hauteur'])))
416
+        or !$ret['largeur']
417
+        or !($ret['largeur'] = intval(round($ret['largeur'])))
418
+    ) {
419
+        return false;
420
+    }
421
+
422
+    // les images calculees dependent du chemin du fichier source
423
+    // 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
424
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
425
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
426
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
427
+    // alors que ca concerne peu de site au final
428
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
429
+    $identifiant = $fichier;
430
+
431
+    // cas general :
432
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
433
+    // cas particulier de reduire :
434
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
435
+    $cache = 'cache-gd2';
436
+    if (substr($effet, 0, 7) == 'reduire') {
437
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
438
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
439
+        $ret['largeur_dest'] = $destWidth;
440
+        $ret['hauteur_dest'] = $destHeight;
441
+        $effet = "L{$destWidth}xH$destHeight";
442
+        $cache = 'cache-vignettes';
443
+        $fichier_dest = basename($fichier_dest);
444
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
445
+            // on garde la terminaison initiale car image simplement copiee
446
+            // et on postfixe son nom avec un md5 du path
447
+            $terminaison_dest = $terminaison;
448
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
449
+        } else {
450
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
451
+        }
452
+        $cache = sous_repertoire(_DIR_VAR, $cache);
453
+        $cache = sous_repertoire($cache, $effet);
454
+    } else {
455
+        $fichier_dest = md5("$identifiant-$effet");
456
+        $cache = sous_repertoire(_DIR_VAR, $cache);
457
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
458
+        $fichier_dest = substr($fichier_dest, 2);
459
+    }
460
+
461
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
462
+
463
+    $GLOBALS['images_calculees'][] = $fichier_dest;
464
+
465
+    $creer = true;
466
+    // si recalcul des images demande, recalculer chaque image une fois
467
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
468
+        $images_recalcul[$fichier_dest] = true;
469
+    } else {
470
+        if (@file_exists($f = $fichier_dest)) {
471
+            if (filemtime($f) >= $date_src) {
472
+                $creer = false;
473
+            }
474
+        } else {
475
+            if (
476
+                @file_exists($f = "$fichier_dest.src")
477
+                and lire_fichier($f, $valeurs)
478
+                and $valeurs = unserialize($valeurs)
479
+                and $valeurs['date'] >= $date_src
480
+            ) {
481
+                $creer = false;
482
+            }
483
+        }
484
+    }
485
+    if ($creer) {
486
+        if (!@file_exists($fichier)) {
487
+            if (!@file_exists("$fichier.src")) {
488
+                spip_log("Image absente : $fichier");
489
+
490
+                return false;
491
+            }
492
+            # on reconstruit l'image source absente a partir de la chaine des .src
493
+            reconstruire_image_intermediaire($fichier);
494
+        }
495
+    }
496
+
497
+    if ($creer) {
498
+        spip_log(
499
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
500
+            'images' . _LOG_DEBUG
501
+        );
502
+    }
503
+
504
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
505
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
506
+    $ret['fichier'] = $fichier;
507
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
508
+    $ret['fichier_dest'] = $fichier_dest;
509
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
510
+    $ret['format_dest'] = $terminaison_dest;
511
+    $ret['date_src'] = $date_src;
512
+    $ret['creer'] = $creer;
513
+    $ret['class'] = extraire_attribut($img, 'class');
514
+    $ret['alt'] = extraire_attribut($img, 'alt');
515
+    $ret['style'] = extraire_attribut($img, 'style');
516
+    $ret['tag'] = $img;
517
+    if ($fonction_creation) {
518
+        $ret['reconstruction'] = $fonction_creation;
519
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
520
+        # cas de image_reduire qui finalement ne reduit pas l'image source
521
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
522
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
523
+    }
524
+
525
+    $ret = pipeline('image_preparer_filtre', [
526
+            'args' => [
527
+                'img' => $img,
528
+                'effet' => $effet,
529
+                'forcer_format' => $forcer_format,
530
+                'fonction_creation' => $fonction_creation,
531
+                'find_in_path' => $find_in_path,
532
+            ],
533
+            'data' => $ret
534
+        ]);
535
+
536
+    // une globale pour le debug en cas de crash memoire
537
+    $GLOBALS['derniere_image_calculee'] = $ret;
538
+
539
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
540
+    if ($term_fonction === 'svg') {
541
+        if ($creer and !$support_svg) {
542
+            process_image_svg_identite($ret);
543
+            $ret['creer'] = false;
544
+        }
545
+    }
546
+    else {
547
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
548
+            return false;
549
+        }
550
+    }
551
+
552
+    return $ret;
553 553
 }
554 554
 
555 555
 
@@ -558,54 +558,54 @@  discard block
 block discarded – undo
558 558
  * @return array
559 559
  */
560 560
 function _image_extensions_acceptees_en_entree() {
561
-	static $extensions = null;
562
-	if (empty($extensions)) {
563
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
564
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
565
-			// action=tester renseigne gd_formats et detecte le support de webp
566
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
567
-			$extensions = array_map('trim', $extensions);
568
-			$extensions = array_filter($extensions);
569
-			if (in_array('jpg', $extensions)) {
570
-				$extensions[] = 'jpeg';
571
-			}
572
-			$extensions = array_unique($extensions);
573
-		}
574
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
575
-	}
576
-
577
-	return $extensions;
561
+    static $extensions = null;
562
+    if (empty($extensions)) {
563
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
564
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
565
+            // action=tester renseigne gd_formats et detecte le support de webp
566
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
567
+            $extensions = array_map('trim', $extensions);
568
+            $extensions = array_filter($extensions);
569
+            if (in_array('jpg', $extensions)) {
570
+                $extensions[] = 'jpeg';
571
+            }
572
+            $extensions = array_unique($extensions);
573
+        }
574
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
575
+    }
576
+
577
+    return $extensions;
578 578
 }
579 579
 
580 580
 /**
581 581
  * @return array|string[]|null
582 582
  */
583 583
 function _image_extensions_acceptees_en_sortie() {
584
-	static $extensions = null;
585
-	if (empty($extensions)) {
586
-		$extensions = _image_extensions_acceptees_en_entree();
587
-		$extensions = array_diff($extensions, ['jpeg']);
588
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
589
-			$extensions = array_diff($extensions, ['gif']);
590
-		}
591
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
592
-			$extensions = array_diff($extensions, ['webp']);
593
-		}
594
-	}
595
-
596
-	return $extensions;
584
+    static $extensions = null;
585
+    if (empty($extensions)) {
586
+        $extensions = _image_extensions_acceptees_en_entree();
587
+        $extensions = array_diff($extensions, ['jpeg']);
588
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
589
+            $extensions = array_diff($extensions, ['gif']);
590
+        }
591
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
592
+            $extensions = array_diff($extensions, ['webp']);
593
+        }
594
+    }
595
+
596
+    return $extensions;
597 597
 }
598 598
 
599 599
 function _image_extension_normalisee($extension) {
600
-	$extension = strtolower($extension);
601
-	if ($extension === 'jpeg') {
602
-		$extension = 'jpg';
603
-	}
604
-	return $extension;
600
+    $extension = strtolower($extension);
601
+    if ($extension === 'jpeg') {
602
+        $extension = 'jpg';
603
+    }
604
+    return $extension;
605 605
 }
606 606
 
607 607
 function _image_extensions_conservent_transparence() {
608
-	return ['png', 'webp'];
608
+    return ['png', 'webp'];
609 609
 }
610 610
 
611 611
 
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
  * @return string
616 616
  */
617 617
 function _image_trouver_extension($path) {
618
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
619
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
620
-		$terminaison = strtolower($regs[1]);
621
-		return $terminaison;
622
-	}
623
-	return '';
618
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
619
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
620
+        $terminaison = strtolower($regs[1]);
621
+        return $terminaison;
622
+    }
623
+    return '';
624 624
 }
625 625
 
626 626
 /**
@@ -631,33 +631,33 @@  discard block
 block discarded – undo
631 631
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
632 632
  */
633 633
 function _image_trouver_extension_pertinente($path) {
634
-	$path = supprimer_timestamp($path);
635
-	$terminaison = _image_trouver_extension($path);
636
-	if ($terminaison == 'jpg') {
637
-		$terminaison = 'jpeg';
638
-	}
639
-
640
-	if (!file_exists($path)) {
641
-		return $terminaison;
642
-	}
643
-
644
-	if (!$info = @spip_getimagesize($path)) {
645
-		return $terminaison;
646
-	}
647
-
648
-	if (isset($info['mime'])) {
649
-		$mime = $info['mime'];
650
-	}
651
-	else {
652
-		$mime = image_type_to_mime_type($info[2]);
653
-	}
654
-
655
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
656
-	if ($_terminaison and $_terminaison !== $terminaison) {
657
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
658
-		$terminaison = $_terminaison;
659
-	}
660
-	return $terminaison;
634
+    $path = supprimer_timestamp($path);
635
+    $terminaison = _image_trouver_extension($path);
636
+    if ($terminaison == 'jpg') {
637
+        $terminaison = 'jpeg';
638
+    }
639
+
640
+    if (!file_exists($path)) {
641
+        return $terminaison;
642
+    }
643
+
644
+    if (!$info = @spip_getimagesize($path)) {
645
+        return $terminaison;
646
+    }
647
+
648
+    if (isset($info['mime'])) {
649
+        $mime = $info['mime'];
650
+    }
651
+    else {
652
+        $mime = image_type_to_mime_type($info[2]);
653
+    }
654
+
655
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
656
+    if ($_terminaison and $_terminaison !== $terminaison) {
657
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
658
+        $terminaison = $_terminaison;
659
+    }
660
+    return $terminaison;
661 661
 }
662 662
 
663 663
 /**
@@ -665,36 +665,36 @@  discard block
 block discarded – undo
665 665
  * @return string
666 666
  */
667 667
 function _image_trouver_extension_depuis_mime($mime) {
668
-	switch (strtolower($mime)) {
669
-		case 'image/png':
670
-		case 'image/x-png':
671
-			$terminaison = 'png';
672
-			break;
673
-
674
-		case 'image/jpg':
675
-		case 'image/jpeg':
676
-		case 'image/pjpeg':
677
-			$terminaison = 'jpeg';
678
-			break;
679
-
680
-		case 'image/gif':
681
-			$terminaison = 'gif';
682
-			break;
683
-
684
-		case 'image/webp':
685
-		case 'image/x-webp':
686
-			$terminaison = 'webp';
687
-			break;
688
-
689
-		case 'image/svg+xml':
690
-			$terminaison = 'svg';
691
-			break;
692
-
693
-		default:
694
-			$terminaison = '';
695
-	}
696
-
697
-	return $terminaison;
668
+    switch (strtolower($mime)) {
669
+        case 'image/png':
670
+        case 'image/x-png':
671
+            $terminaison = 'png';
672
+            break;
673
+
674
+        case 'image/jpg':
675
+        case 'image/jpeg':
676
+        case 'image/pjpeg':
677
+            $terminaison = 'jpeg';
678
+            break;
679
+
680
+        case 'image/gif':
681
+            $terminaison = 'gif';
682
+            break;
683
+
684
+        case 'image/webp':
685
+        case 'image/x-webp':
686
+            $terminaison = 'webp';
687
+            break;
688
+
689
+        case 'image/svg+xml':
690
+            $terminaison = 'svg';
691
+            break;
692
+
693
+        default:
694
+            $terminaison = '';
695
+    }
696
+
697
+    return $terminaison;
698 698
 }
699 699
 
700 700
 
@@ -714,18 +714,18 @@  discard block
 block discarded – undo
714 714
  *     Une ressource de type Image GD.
715 715
  */
716 716
 function _imagecreatefrom_func(string $func, string $filename) {
717
-	if (!function_exists($func)) {
718
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
719
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
720
-		return null;
721
-	}
722
-	$img = @$func($filename);
723
-	if (!$img) {
724
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
725
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
726
-		$img = imagecreate(10, 10);
727
-	}
728
-	return $img;
717
+    if (!function_exists($func)) {
718
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
719
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
720
+        return null;
721
+    }
722
+    $img = @$func($filename);
723
+    if (!$img) {
724
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
725
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
726
+        $img = imagecreate(10, 10);
727
+    }
728
+    return $img;
729 729
 }
730 730
 
731 731
 /**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
  *     Une ressource de type Image GD.
742 742
  */
743 743
 function _imagecreatefromjpeg($filename) {
744
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
744
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
745 745
 }
746 746
 
747 747
 /**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
  *     Une ressource de type Image GD.
758 758
  */
759 759
 function _imagecreatefrompng($filename) {
760
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
760
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
761 761
 }
762 762
 
763 763
 /**
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
  *     Une ressource de type Image GD.
774 774
  */
775 775
 function _imagecreatefromgif($filename) {
776
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
776
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
777 777
 }
778 778
 
779 779
 
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
  *     Une ressource de type Image GD.
791 791
  */
792 792
 function _imagecreatefromwebp($filename) {
793
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
793
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
794 794
 }
795 795
 
796 796
 /**
@@ -808,24 +808,24 @@  discard block
 block discarded – undo
808 808
  *     - true si une image est bien retournée.
809 809
  */
810 810
 function _image_imagepng($img, $fichier) {
811
-	if (!function_exists('imagepng')) {
812
-		return false;
813
-	}
814
-	$tmp = $fichier . '.tmp';
815
-	$ret = imagepng($img, $tmp);
816
-	if (file_exists($tmp)) {
817
-		$taille_test = @getimagesize($tmp);
818
-		if (empty($taille_test[0])) {
819
-			return false;
820
-		}
821
-
822
-		spip_unlink($fichier); // le fichier peut deja exister
823
-		@rename($tmp, $fichier);
824
-
825
-		return $ret;
826
-	}
827
-
828
-	return false;
811
+    if (!function_exists('imagepng')) {
812
+        return false;
813
+    }
814
+    $tmp = $fichier . '.tmp';
815
+    $ret = imagepng($img, $tmp);
816
+    if (file_exists($tmp)) {
817
+        $taille_test = @getimagesize($tmp);
818
+        if (empty($taille_test[0])) {
819
+            return false;
820
+        }
821
+
822
+        spip_unlink($fichier); // le fichier peut deja exister
823
+        @rename($tmp, $fichier);
824
+
825
+        return $ret;
826
+    }
827
+
828
+    return false;
829 829
 }
830 830
 
831 831
 /**
@@ -843,24 +843,24 @@  discard block
 block discarded – undo
843 843
  *     - true si une image est bien retournée.
844 844
  */
845 845
 function _image_imagegif($img, $fichier) {
846
-	if (!function_exists('imagegif')) {
847
-		return false;
848
-	}
849
-	$tmp = $fichier . '.tmp';
850
-	$ret = imagegif($img, $tmp);
851
-	if (file_exists($tmp)) {
852
-		$taille_test = @getimagesize($tmp);
853
-		if (empty($taille_test[0])) {
854
-			return false;
855
-		}
856
-
857
-		spip_unlink($fichier); // le fichier peut deja exister
858
-		@rename($tmp, $fichier);
859
-
860
-		return $ret;
861
-	}
862
-
863
-	return false;
846
+    if (!function_exists('imagegif')) {
847
+        return false;
848
+    }
849
+    $tmp = $fichier . '.tmp';
850
+    $ret = imagegif($img, $tmp);
851
+    if (file_exists($tmp)) {
852
+        $taille_test = @getimagesize($tmp);
853
+        if (empty($taille_test[0])) {
854
+            return false;
855
+        }
856
+
857
+        spip_unlink($fichier); // le fichier peut deja exister
858
+        @rename($tmp, $fichier);
859
+
860
+        return $ret;
861
+    }
862
+
863
+    return false;
864 864
 }
865 865
 
866 866
 /**
@@ -883,29 +883,29 @@  discard block
 block discarded – undo
883 883
  *     - true si une image est bien retournée.
884 884
  */
885 885
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
886
-	if (!function_exists('imagejpeg')) {
887
-		return false;
888
-	}
889
-	$tmp = $fichier . '.tmp';
886
+    if (!function_exists('imagejpeg')) {
887
+        return false;
888
+    }
889
+    $tmp = $fichier . '.tmp';
890 890
 
891
-	// Enable interlancing
892
-	imageinterlace($img, true);
891
+    // Enable interlancing
892
+    imageinterlace($img, true);
893 893
 
894
-	$ret = imagejpeg($img, $tmp, $qualite);
894
+    $ret = imagejpeg($img, $tmp, $qualite);
895 895
 
896
-	if (file_exists($tmp)) {
897
-		$taille_test = @getimagesize($tmp);
898
-		if (empty($taille_test[0])) {
899
-			return false;
900
-		}
896
+    if (file_exists($tmp)) {
897
+        $taille_test = @getimagesize($tmp);
898
+        if (empty($taille_test[0])) {
899
+            return false;
900
+        }
901 901
 
902
-		spip_unlink($fichier); // le fichier peut deja exister
903
-		@rename($tmp, $fichier);
902
+        spip_unlink($fichier); // le fichier peut deja exister
903
+        @rename($tmp, $fichier);
904 904
 
905
-		return $ret;
906
-	}
905
+        return $ret;
906
+    }
907 907
 
908
-	return false;
908
+    return false;
909 909
 }
910 910
 
911 911
 /**
@@ -923,9 +923,9 @@  discard block
 block discarded – undo
923 923
  *     true si le fichier a bien été créé ; false sinon.
924 924
  */
925 925
 function _image_imageico($img, $fichier) {
926
-	$gd_image_array = [$img];
926
+    $gd_image_array = [$img];
927 927
 
928
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
928
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
929 929
 }
930 930
 
931 931
 
@@ -944,24 +944,24 @@  discard block
 block discarded – undo
944 944
  *     - true si une image est bien retournée.
945 945
  */
946 946
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
947
-	if (!function_exists('imagewebp')) {
948
-		return false;
949
-	}
950
-	$tmp = $fichier . '.tmp';
951
-	$ret = imagewebp($img, $tmp, $qualite);
952
-	if (file_exists($tmp)) {
953
-		$taille_test = @getimagesize($tmp);
954
-		if (empty($taille_test[0])) {
955
-			return false;
956
-		}
957
-
958
-		spip_unlink($fichier); // le fichier peut deja exister
959
-		@rename($tmp, $fichier);
960
-
961
-		return $ret;
962
-	}
963
-
964
-	return false;
947
+    if (!function_exists('imagewebp')) {
948
+        return false;
949
+    }
950
+    $tmp = $fichier . '.tmp';
951
+    $ret = imagewebp($img, $tmp, $qualite);
952
+    if (file_exists($tmp)) {
953
+        $taille_test = @getimagesize($tmp);
954
+        if (empty($taille_test[0])) {
955
+            return false;
956
+        }
957
+
958
+        spip_unlink($fichier); // le fichier peut deja exister
959
+        @rename($tmp, $fichier);
960
+
961
+        return $ret;
962
+    }
963
+
964
+    return false;
965 965
 }
966 966
 
967 967
 /**
@@ -981,35 +981,35 @@  discard block
 block discarded – undo
981 981
  */
982 982
 function _image_imagesvg($img, $fichier) {
983 983
 
984
-	$tmp = $fichier . '.tmp';
985
-	if (strpos($img, '<') === false) {
986
-		$img = supprimer_timestamp($img);
987
-		if (!file_exists($img)) {
988
-			return false;
989
-		}
990
-		@copy($img, $tmp);
991
-		if (filesize($tmp) == filesize($img)) {
992
-			spip_unlink($fichier); // le fichier peut deja exister
993
-			@rename($tmp, $fichier);
994
-			return true;
995
-		}
996
-		return false;
997
-	}
998
-
999
-	file_put_contents($tmp, $img);
1000
-	if (file_exists($tmp)) {
1001
-		$taille_test = spip_getimagesize($tmp);
1002
-		if (empty($taille_test[0])) {
1003
-			return false;
1004
-		}
1005
-
1006
-		spip_unlink($fichier); // le fichier peut deja exister
1007
-		@rename($tmp, $fichier);
1008
-
1009
-		return true;
1010
-	}
1011
-
1012
-	return false;
984
+    $tmp = $fichier . '.tmp';
985
+    if (strpos($img, '<') === false) {
986
+        $img = supprimer_timestamp($img);
987
+        if (!file_exists($img)) {
988
+            return false;
989
+        }
990
+        @copy($img, $tmp);
991
+        if (filesize($tmp) == filesize($img)) {
992
+            spip_unlink($fichier); // le fichier peut deja exister
993
+            @rename($tmp, $fichier);
994
+            return true;
995
+        }
996
+        return false;
997
+    }
998
+
999
+    file_put_contents($tmp, $img);
1000
+    if (file_exists($tmp)) {
1001
+        $taille_test = spip_getimagesize($tmp);
1002
+        if (empty($taille_test[0])) {
1003
+            return false;
1004
+        }
1005
+
1006
+        spip_unlink($fichier); // le fichier peut deja exister
1007
+        @rename($tmp, $fichier);
1008
+
1009
+        return true;
1010
+    }
1011
+
1012
+    return false;
1013 1013
 }
1014 1014
 
1015 1015
 
@@ -1037,30 +1037,30 @@  discard block
 block discarded – undo
1037 1037
  *     - false sinon.
1038 1038
  */
1039 1039
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1040
-	if (is_null($fonction)) {
1041
-		$fonction = '_image_image' . $valeurs['format_dest'];
1042
-	}
1043
-	$ret = false;
1044
-	#un flag pour reperer les images gravees
1045
-	$lock = (
1046
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1047
-		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1048
-	);
1049
-	if (
1050
-		function_exists($fonction)
1051
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1052
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1053
-		&& !$lock
1054
-	) {
1055
-		if (@file_exists($valeurs['fichier_dest'])) {
1056
-			// dans tous les cas mettre a jour la taille de l'image finale
1057
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1058
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1059
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1060
-		}
1061
-	}
1062
-
1063
-	return $ret;
1040
+    if (is_null($fonction)) {
1041
+        $fonction = '_image_image' . $valeurs['format_dest'];
1042
+    }
1043
+    $ret = false;
1044
+    #un flag pour reperer les images gravees
1045
+    $lock = (
1046
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1047
+        or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1048
+    );
1049
+    if (
1050
+        function_exists($fonction)
1051
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1052
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1053
+        && !$lock
1054
+    ) {
1055
+        if (@file_exists($valeurs['fichier_dest'])) {
1056
+            // dans tous les cas mettre a jour la taille de l'image finale
1057
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1058
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1059
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1060
+        }
1061
+    }
1062
+
1063
+    return $ret;
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1073,27 +1073,27 @@  discard block
 block discarded – undo
1073 1073
  *     Chemin vers le fichier manquant
1074 1074
  **/
1075 1075
 function reconstruire_image_intermediaire($fichier_manquant) {
1076
-	$reconstruire = [];
1077
-	$fichier = $fichier_manquant;
1078
-	while (
1079
-		strpos($fichier, '://') === false
1080
-		and !@file_exists($fichier)
1081
-		and lire_fichier($src = "$fichier.src", $source)
1082
-		and $valeurs = unserialize($source)
1083
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1084
-	) {
1085
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1086
-		$reconstruire[] = $valeurs['reconstruction'];
1087
-	}
1088
-	while (count($reconstruire)) {
1089
-		$r = array_pop($reconstruire);
1090
-		$fonction = $r[0];
1091
-		$args = $r[1];
1092
-		$fonction(...$args);
1093
-	}
1094
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1095
-	// mais l'on peut nettoyer les miettes de sa creation
1096
-	ramasse_miettes($fichier_manquant);
1076
+    $reconstruire = [];
1077
+    $fichier = $fichier_manquant;
1078
+    while (
1079
+        strpos($fichier, '://') === false
1080
+        and !@file_exists($fichier)
1081
+        and lire_fichier($src = "$fichier.src", $source)
1082
+        and $valeurs = unserialize($source)
1083
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1084
+    ) {
1085
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1086
+        $reconstruire[] = $valeurs['reconstruction'];
1087
+    }
1088
+    while (count($reconstruire)) {
1089
+        $r = array_pop($reconstruire);
1090
+        $fonction = $r[0];
1091
+        $args = $r[1];
1092
+        $fonction(...$args);
1093
+    }
1094
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1095
+    // mais l'on peut nettoyer les miettes de sa creation
1096
+    ramasse_miettes($fichier_manquant);
1097 1097
 }
1098 1098
 
1099 1099
 /**
@@ -1113,28 +1113,28 @@  discard block
 block discarded – undo
1113 1113
  *     Chemin du fichier d'image calculé
1114 1114
  **/
1115 1115
 function ramasse_miettes($fichier) {
1116
-	if (
1117
-		strpos($fichier, '://') !== false
1118
-		or !lire_fichier($src = "$fichier.src", $source)
1119
-		or !$valeurs = unserialize($source)
1120
-	) {
1121
-		return;
1122
-	}
1123
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1124
-	while (
1125
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1126
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1127
-		and (lire_fichier(
1128
-			$src = "$fichier.src",
1129
-			$source
1130
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1131
-		and ($valeurs = unserialize($source))  # et valide
1132
-	) {
1133
-		# on efface le fichier
1134
-		spip_unlink($fichier);
1135
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1136
-		#spip_unlink($src);
1137
-	}
1116
+    if (
1117
+        strpos($fichier, '://') !== false
1118
+        or !lire_fichier($src = "$fichier.src", $source)
1119
+        or !$valeurs = unserialize($source)
1120
+    ) {
1121
+        return;
1122
+    }
1123
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1124
+    while (
1125
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1126
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1127
+        and (lire_fichier(
1128
+            $src = "$fichier.src",
1129
+            $source
1130
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1131
+        and ($valeurs = unserialize($source))  # et valide
1132
+    ) {
1133
+        # on efface le fichier
1134
+        spip_unlink($fichier);
1135
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1136
+        #spip_unlink($src);
1137
+    }
1138 1138
 }
1139 1139
 
1140 1140
 
@@ -1159,31 +1159,31 @@  discard block
 block discarded – undo
1159 1159
  *     Code HTML de l'image
1160 1160
  **/
1161 1161
 function image_graver($img) {
1162
-	// appeler le filtre post_image_filtrer qui permet de faire
1163
-	// des traitements auto a la fin d'une serie de filtres
1164
-	$img = pipeline('post_image_filtrer', $img);
1165
-
1166
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1167
-	if (($p = strpos($fichier, '?')) !== false) {
1168
-		$fichier = substr($fichier, 0, $p);
1169
-	}
1170
-	if (strlen($fichier) < 1) {
1171
-		$fichier = $img;
1172
-	}
1173
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1174
-	# et qu'il ne s'agit pas d'une URL
1175
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1176
-		reconstruire_image_intermediaire($fichier);
1177
-	}
1178
-	ramasse_miettes($fichier);
1179
-
1180
-	// ajouter le timestamp si besoin
1181
-	if (strpos($fichier_ori, '?') === false) {
1182
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1183
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1184
-	}
1185
-
1186
-	return $img;
1162
+    // appeler le filtre post_image_filtrer qui permet de faire
1163
+    // des traitements auto a la fin d'une serie de filtres
1164
+    $img = pipeline('post_image_filtrer', $img);
1165
+
1166
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1167
+    if (($p = strpos($fichier, '?')) !== false) {
1168
+        $fichier = substr($fichier, 0, $p);
1169
+    }
1170
+    if (strlen($fichier) < 1) {
1171
+        $fichier = $img;
1172
+    }
1173
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1174
+    # et qu'il ne s'agit pas d'une URL
1175
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1176
+        reconstruire_image_intermediaire($fichier);
1177
+    }
1178
+    ramasse_miettes($fichier);
1179
+
1180
+    // ajouter le timestamp si besoin
1181
+    if (strpos($fichier_ori, '?') === false) {
1182
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1183
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1184
+    }
1185
+
1186
+    return $img;
1187 1187
 }
1188 1188
 
1189 1189
 /**
@@ -1210,34 +1210,34 @@  discard block
 block discarded – undo
1210 1210
  *     Code html modifié de la balise.
1211 1211
  **/
1212 1212
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1213
-	if ($style === false) {
1214
-		$style = extraire_attribut($tag, 'style');
1215
-	}
1216
-
1217
-	// enlever le width et height du style
1218
-	if ($style) {
1219
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1220
-	}
1221
-	if ($style and $style[0] === ';') {
1222
-		$style = substr($style, 1);
1223
-	}
1224
-
1225
-	// mettre des attributs de width et height sur les images,
1226
-	// ca accelere le rendu du navigateur
1227
-	// ca permet aux navigateurs de reserver la bonne taille
1228
-	// quand on a desactive l'affichage des images.
1229
-	$tag = inserer_attribut($tag, 'width', round($width));
1230
-	$tag = inserer_attribut($tag, 'height', round($height));
1231
-
1232
-	// attributs deprecies. Transformer en CSS
1233
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1234
-		$style = "margin:{$espace}px;" . $style;
1235
-		$tag = inserer_attribut($tag, 'hspace', '');
1236
-	}
1237
-
1238
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1239
-
1240
-	return $tag;
1213
+    if ($style === false) {
1214
+        $style = extraire_attribut($tag, 'style');
1215
+    }
1216
+
1217
+    // enlever le width et height du style
1218
+    if ($style) {
1219
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1220
+    }
1221
+    if ($style and $style[0] === ';') {
1222
+        $style = substr($style, 1);
1223
+    }
1224
+
1225
+    // mettre des attributs de width et height sur les images,
1226
+    // ca accelere le rendu du navigateur
1227
+    // ca permet aux navigateurs de reserver la bonne taille
1228
+    // quand on a desactive l'affichage des images.
1229
+    $tag = inserer_attribut($tag, 'width', round($width));
1230
+    $tag = inserer_attribut($tag, 'height', round($height));
1231
+
1232
+    // attributs deprecies. Transformer en CSS
1233
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1234
+        $style = "margin:{$espace}px;" . $style;
1235
+        $tag = inserer_attribut($tag, 'hspace', '');
1236
+    }
1237
+
1238
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1239
+
1240
+    return $tag;
1241 1241
 }
1242 1242
 
1243 1243
 
@@ -1263,72 +1263,72 @@  discard block
 block discarded – undo
1263 1263
  *     Retourne le code HTML de l'image
1264 1264
  **/
1265 1265
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1266
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1267
-
1268
-	// fermer les tags img pas bien fermes;
1269
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1270
-
1271
-	// le style
1272
-	$style = $valeurs['style'];
1273
-	if (isset($surcharge['style'])) {
1274
-		$style = $surcharge['style'];
1275
-		unset($surcharge['style']);
1276
-	}
1277
-
1278
-	// traiter specifiquement la largeur et la hauteur
1279
-	$width = $valeurs['largeur'];
1280
-	if (isset($surcharge['width'])) {
1281
-		$width = $surcharge['width'];
1282
-		unset($surcharge['width']);
1283
-	}
1284
-	$height = $valeurs['hauteur'];
1285
-	if (isset($surcharge['height'])) {
1286
-		$height = $surcharge['height'];
1287
-		unset($surcharge['height']);
1288
-	}
1289
-
1290
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1291
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1292
-	// on remplace toute les ref a src dans le tag
1293
-	$src = extraire_attribut($tag, 'src');
1294
-	if (isset($surcharge['src'])) {
1295
-		$tag = str_replace($src, $surcharge['src'], $tag);
1296
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1297
-		// pas garanti comme methode, mais mieux que rien
1298
-		if (strpos($src, '&') !== false) {
1299
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1300
-		}
1301
-		$src = $surcharge['src'];
1302
-		unset($surcharge['src']);
1303
-	}
1304
-
1305
-	$class = $valeurs['class'];
1306
-	if (isset($surcharge['class'])) {
1307
-		$class = $surcharge['class'];
1308
-		unset($surcharge['class']);
1309
-	}
1310
-	if (is_scalar($class) && strlen($class)) {
1311
-		$tag = inserer_attribut($tag, 'class', $class);
1312
-	}
1313
-
1314
-	if (count($surcharge)) {
1315
-		foreach ($surcharge as $attribut => $valeur) {
1316
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1317
-		}
1318
-	}
1319
-
1320
-	$tag = pipeline(
1321
-		'image_ecrire_tag_finir',
1322
-		[
1323
-			'args' => [
1324
-				'valeurs' => $valeurs,
1325
-				'surcharge' => $surcharge,
1326
-			],
1327
-			'data' => $tag
1328
-		]
1329
-	);
1330
-
1331
-	return $tag;
1266
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1267
+
1268
+    // fermer les tags img pas bien fermes;
1269
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1270
+
1271
+    // le style
1272
+    $style = $valeurs['style'];
1273
+    if (isset($surcharge['style'])) {
1274
+        $style = $surcharge['style'];
1275
+        unset($surcharge['style']);
1276
+    }
1277
+
1278
+    // traiter specifiquement la largeur et la hauteur
1279
+    $width = $valeurs['largeur'];
1280
+    if (isset($surcharge['width'])) {
1281
+        $width = $surcharge['width'];
1282
+        unset($surcharge['width']);
1283
+    }
1284
+    $height = $valeurs['hauteur'];
1285
+    if (isset($surcharge['height'])) {
1286
+        $height = $surcharge['height'];
1287
+        unset($surcharge['height']);
1288
+    }
1289
+
1290
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1291
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1292
+    // on remplace toute les ref a src dans le tag
1293
+    $src = extraire_attribut($tag, 'src');
1294
+    if (isset($surcharge['src'])) {
1295
+        $tag = str_replace($src, $surcharge['src'], $tag);
1296
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1297
+        // pas garanti comme methode, mais mieux que rien
1298
+        if (strpos($src, '&') !== false) {
1299
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1300
+        }
1301
+        $src = $surcharge['src'];
1302
+        unset($surcharge['src']);
1303
+    }
1304
+
1305
+    $class = $valeurs['class'];
1306
+    if (isset($surcharge['class'])) {
1307
+        $class = $surcharge['class'];
1308
+        unset($surcharge['class']);
1309
+    }
1310
+    if (is_scalar($class) && strlen($class)) {
1311
+        $tag = inserer_attribut($tag, 'class', $class);
1312
+    }
1313
+
1314
+    if (count($surcharge)) {
1315
+        foreach ($surcharge as $attribut => $valeur) {
1316
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1317
+        }
1318
+    }
1319
+
1320
+    $tag = pipeline(
1321
+        'image_ecrire_tag_finir',
1322
+        [
1323
+            'args' => [
1324
+                'valeurs' => $valeurs,
1325
+                'surcharge' => $surcharge,
1326
+            ],
1327
+            'data' => $tag
1328
+        ]
1329
+    );
1330
+
1331
+    return $tag;
1332 1332
 }
1333 1333
 
1334 1334
 /**
@@ -1351,268 +1351,268 @@  discard block
 block discarded – undo
1351 1351
  *     Description de l'image, sinon null.
1352 1352
  **/
1353 1353
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1354
-	$srcHeight = null;
1355
-	$retour = [];
1356
-	// ordre de preference des formats graphiques pour creer les vignettes
1357
-	// le premier format disponible, selon la methode demandee, est utilise
1358
-	$image = $valeurs['fichier'];
1359
-	$format = $valeurs['format_source'];
1360
-	$destdir = dirname($valeurs['fichier_dest']);
1361
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1362
-
1363
-	$format_sortie = $valeurs['format_dest'];
1364
-
1365
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1366
-		$process = $GLOBALS['meta']['image_process'];
1367
-	}
1368
-
1369
-	// si le doc n'est pas une image dans un format accetpable, refuser
1370
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1371
-		return;
1372
-	}
1373
-	$destination = "$destdir/$destfile";
1374
-
1375
-	// calculer la taille
1376
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1377
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1378
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1379
-		}
1380
-	} elseif ($process == 'convert' or $process == 'imagick') {
1381
-		$destWidth = $maxWidth;
1382
-		$destHeight = $maxHeight;
1383
-	} else {
1384
-		spip_log("echec $process sur $image");
1385
-
1386
-		return;
1387
-	}
1388
-
1389
-	$vignette = '';
1390
-
1391
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1392
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1393
-		$vignette = $destination . '.' . $format;
1394
-		@copy($image, $vignette);
1395
-	}
1396
-
1397
-	elseif ($valeurs['format_source'] === 'svg') {
1398
-		include_spip('inc/svg');
1399
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1400
-			$format_sortie = 'svg';
1401
-			$vignette = $destination . '.' . $format_sortie;
1402
-			$valeurs['fichier_dest'] = $vignette;
1403
-			_image_gd_output($svg, $valeurs);
1404
-		}
1405
-	}
1406
-
1407
-	// imagemagick en ligne de commande
1408
-	elseif ($process == 'convert') {
1409
-		if (!defined('_CONVERT_COMMAND')) {
1410
-			define('_CONVERT_COMMAND', 'convert');
1411
-		} // Securite : mes_options.php peut preciser le chemin absolu
1412
-		if (!defined('_RESIZE_COMMAND')) {
1413
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1414
-		}
1415
-		$vignette = $destination . '.' . $format_sortie;
1416
-		$commande = str_replace(
1417
-			['%x', '%y', '%src', '%dest'],
1418
-			[
1419
-				$destWidth,
1420
-				$destHeight,
1421
-				escapeshellcmd($image),
1422
-				escapeshellcmd($vignette)
1423
-			],
1424
-			_RESIZE_COMMAND
1425
-		);
1426
-		spip_log($commande);
1427
-		exec($commande);
1428
-		if (!@file_exists($vignette)) {
1429
-			spip_log("echec convert sur $vignette");
1430
-
1431
-			return;  // echec commande
1432
-		}
1433
-	}
1434
-
1435
-	// php5 imagemagick
1436
-	elseif ($process == 'imagick') {
1437
-		if (!class_exists(\Imagick::class)) {
1438
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1439
-
1440
-			return;
1441
-		}
1442
-
1443
-		// chemin compatible Windows
1444
-		$output = realpath(dirname($destination));
1445
-		if (!$output) {
1446
-			return;
1447
-		}
1448
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1449
-
1450
-		$imagick = new Imagick();
1451
-		$imagick->readImage(realpath($image));
1452
-		$imagick->resizeImage(
1453
-			$destWidth,
1454
-			$destHeight,
1455
-			Imagick::FILTER_LANCZOS,
1456
-			1
1457
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1458
-		$imagick->writeImage($vignette);
1459
-
1460
-		if (!@file_exists($vignette)) {
1461
-			spip_log("echec imagick sur $vignette");
1462
-
1463
-			return;
1464
-		}
1465
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1466
-		$vignette = $destination . '.' . $format_sortie;
1467
-	}
1468
-
1469
-	// netpbm
1470
-	elseif ($process == 'netpbm') {
1471
-		if (!defined('_PNMSCALE_COMMAND')) {
1472
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1473
-		} // Securite : mes_options.php peut preciser le chemin absolu
1474
-		if (_PNMSCALE_COMMAND == '') {
1475
-			return;
1476
-		}
1477
-		$vignette = $destination . '.' . $format_sortie;
1478
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1479
-		if ($format == 'jpg') {
1480
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1481
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1482
-			if (!($s = @filesize($vignette))) {
1483
-				spip_unlink($vignette);
1484
-			}
1485
-			if (!@file_exists($vignette)) {
1486
-				spip_log("echec netpbm-jpg sur $vignette");
1487
-
1488
-				return;
1489
-			}
1490
-		} else {
1491
-			if ($format == 'gif') {
1492
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1493
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1494
-				if (!($s = @filesize($vignette))) {
1495
-					spip_unlink($vignette);
1496
-				}
1497
-				if (!@file_exists($vignette)) {
1498
-					spip_log("echec netpbm-gif sur $vignette");
1499
-
1500
-					return;
1501
-				}
1502
-			} else {
1503
-				if ($format == 'png') {
1504
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1505
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1506
-					if (!($s = @filesize($vignette))) {
1507
-						spip_unlink($vignette);
1508
-					}
1509
-					if (!@file_exists($vignette)) {
1510
-						spip_log("echec netpbm-png sur $vignette");
1511
-
1512
-						return;
1513
-					}
1514
-				}
1515
-			}
1516
-		}
1517
-	}
1518
-
1519
-	// gd ou gd2
1520
-	elseif ($process == 'gd1' or $process == 'gd2') {
1521
-		if (!function_exists('gd_info')) {
1522
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1523
-
1524
-			return;
1525
-		}
1526
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1527
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1528
-
1529
-			return;
1530
-		}
1531
-		$destFormat = $format_sortie;
1532
-		if (!$destFormat) {
1533
-			spip_log("pas de format pour $image");
1534
-
1535
-			return;
1536
-		}
1537
-
1538
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1539
-		if (!function_exists($fonction_imagecreatefrom)) {
1540
-			return;
1541
-		}
1542
-		$srcImage = @$fonction_imagecreatefrom($image);
1543
-		if (!$srcImage) {
1544
-			spip_log('echec gd1/gd2');
1545
-
1546
-			return;
1547
-		}
1548
-
1549
-		// Initialisation de l'image destination
1550
-		$destImage = null;
1551
-		if ($process == 'gd2' and $destFormat != 'gif') {
1552
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1553
-		}
1554
-		if (!$destImage) {
1555
-			$destImage = ImageCreate($destWidth, $destHeight);
1556
-		}
1557
-
1558
-		// Recopie de l'image d'origine avec adaptation de la taille
1559
-		$ok = false;
1560
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1561
-			if ($format == 'gif') {
1562
-				// Si un GIF est transparent,
1563
-				// fabriquer un PNG transparent
1564
-				$transp = imagecolortransparent($srcImage);
1565
-				if ($transp > 0) {
1566
-					$destFormat = 'png';
1567
-				}
1568
-			}
1569
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1570
-				// Conserver la transparence
1571
-				if (function_exists('imageAntiAlias')) {
1572
-					imageAntiAlias($destImage, true);
1573
-				}
1574
-				@imagealphablending($destImage, false);
1575
-				@imagesavealpha($destImage, true);
1576
-			}
1577
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1578
-		}
1579
-		if (!$ok) {
1580
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1581
-		}
1582
-
1583
-		// Sauvegarde de l'image destination
1584
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1585
-		$valeurs['format_dest'] = $format = $destFormat;
1586
-		_image_gd_output($destImage, $valeurs);
1587
-
1588
-		if ($srcImage) {
1589
-			ImageDestroy($srcImage);
1590
-		}
1591
-		ImageDestroy($destImage);
1592
-	}
1593
-
1594
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1595
-		$size = [$destWidth, $destHeight];
1596
-	}
1597
-
1598
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1599
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1600
-	if ($size[0] < 1) {
1601
-		$size[0] = $destWidth;
1602
-	}
1603
-	if ($size[1] < 1) {
1604
-		$size[1] = $destHeight;
1605
-	}
1606
-
1607
-	$retour['width'] = $largeur = $size[0];
1608
-	$retour['height'] = $hauteur = $size[1];
1609
-
1610
-	$retour['fichier'] = $vignette;
1611
-	$retour['format'] = $format;
1612
-	$retour['date'] = @filemtime($vignette);
1613
-
1614
-	// renvoyer l'image
1615
-	return $retour;
1354
+    $srcHeight = null;
1355
+    $retour = [];
1356
+    // ordre de preference des formats graphiques pour creer les vignettes
1357
+    // le premier format disponible, selon la methode demandee, est utilise
1358
+    $image = $valeurs['fichier'];
1359
+    $format = $valeurs['format_source'];
1360
+    $destdir = dirname($valeurs['fichier_dest']);
1361
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1362
+
1363
+    $format_sortie = $valeurs['format_dest'];
1364
+
1365
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1366
+        $process = $GLOBALS['meta']['image_process'];
1367
+    }
1368
+
1369
+    // si le doc n'est pas une image dans un format accetpable, refuser
1370
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1371
+        return;
1372
+    }
1373
+    $destination = "$destdir/$destfile";
1374
+
1375
+    // calculer la taille
1376
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1377
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1378
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1379
+        }
1380
+    } elseif ($process == 'convert' or $process == 'imagick') {
1381
+        $destWidth = $maxWidth;
1382
+        $destHeight = $maxHeight;
1383
+    } else {
1384
+        spip_log("echec $process sur $image");
1385
+
1386
+        return;
1387
+    }
1388
+
1389
+    $vignette = '';
1390
+
1391
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1392
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1393
+        $vignette = $destination . '.' . $format;
1394
+        @copy($image, $vignette);
1395
+    }
1396
+
1397
+    elseif ($valeurs['format_source'] === 'svg') {
1398
+        include_spip('inc/svg');
1399
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1400
+            $format_sortie = 'svg';
1401
+            $vignette = $destination . '.' . $format_sortie;
1402
+            $valeurs['fichier_dest'] = $vignette;
1403
+            _image_gd_output($svg, $valeurs);
1404
+        }
1405
+    }
1406
+
1407
+    // imagemagick en ligne de commande
1408
+    elseif ($process == 'convert') {
1409
+        if (!defined('_CONVERT_COMMAND')) {
1410
+            define('_CONVERT_COMMAND', 'convert');
1411
+        } // Securite : mes_options.php peut preciser le chemin absolu
1412
+        if (!defined('_RESIZE_COMMAND')) {
1413
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1414
+        }
1415
+        $vignette = $destination . '.' . $format_sortie;
1416
+        $commande = str_replace(
1417
+            ['%x', '%y', '%src', '%dest'],
1418
+            [
1419
+                $destWidth,
1420
+                $destHeight,
1421
+                escapeshellcmd($image),
1422
+                escapeshellcmd($vignette)
1423
+            ],
1424
+            _RESIZE_COMMAND
1425
+        );
1426
+        spip_log($commande);
1427
+        exec($commande);
1428
+        if (!@file_exists($vignette)) {
1429
+            spip_log("echec convert sur $vignette");
1430
+
1431
+            return;  // echec commande
1432
+        }
1433
+    }
1434
+
1435
+    // php5 imagemagick
1436
+    elseif ($process == 'imagick') {
1437
+        if (!class_exists(\Imagick::class)) {
1438
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1439
+
1440
+            return;
1441
+        }
1442
+
1443
+        // chemin compatible Windows
1444
+        $output = realpath(dirname($destination));
1445
+        if (!$output) {
1446
+            return;
1447
+        }
1448
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1449
+
1450
+        $imagick = new Imagick();
1451
+        $imagick->readImage(realpath($image));
1452
+        $imagick->resizeImage(
1453
+            $destWidth,
1454
+            $destHeight,
1455
+            Imagick::FILTER_LANCZOS,
1456
+            1
1457
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1458
+        $imagick->writeImage($vignette);
1459
+
1460
+        if (!@file_exists($vignette)) {
1461
+            spip_log("echec imagick sur $vignette");
1462
+
1463
+            return;
1464
+        }
1465
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1466
+        $vignette = $destination . '.' . $format_sortie;
1467
+    }
1468
+
1469
+    // netpbm
1470
+    elseif ($process == 'netpbm') {
1471
+        if (!defined('_PNMSCALE_COMMAND')) {
1472
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1473
+        } // Securite : mes_options.php peut preciser le chemin absolu
1474
+        if (_PNMSCALE_COMMAND == '') {
1475
+            return;
1476
+        }
1477
+        $vignette = $destination . '.' . $format_sortie;
1478
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1479
+        if ($format == 'jpg') {
1480
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1481
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1482
+            if (!($s = @filesize($vignette))) {
1483
+                spip_unlink($vignette);
1484
+            }
1485
+            if (!@file_exists($vignette)) {
1486
+                spip_log("echec netpbm-jpg sur $vignette");
1487
+
1488
+                return;
1489
+            }
1490
+        } else {
1491
+            if ($format == 'gif') {
1492
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1493
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1494
+                if (!($s = @filesize($vignette))) {
1495
+                    spip_unlink($vignette);
1496
+                }
1497
+                if (!@file_exists($vignette)) {
1498
+                    spip_log("echec netpbm-gif sur $vignette");
1499
+
1500
+                    return;
1501
+                }
1502
+            } else {
1503
+                if ($format == 'png') {
1504
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1505
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1506
+                    if (!($s = @filesize($vignette))) {
1507
+                        spip_unlink($vignette);
1508
+                    }
1509
+                    if (!@file_exists($vignette)) {
1510
+                        spip_log("echec netpbm-png sur $vignette");
1511
+
1512
+                        return;
1513
+                    }
1514
+                }
1515
+            }
1516
+        }
1517
+    }
1518
+
1519
+    // gd ou gd2
1520
+    elseif ($process == 'gd1' or $process == 'gd2') {
1521
+        if (!function_exists('gd_info')) {
1522
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1523
+
1524
+            return;
1525
+        }
1526
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1527
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1528
+
1529
+            return;
1530
+        }
1531
+        $destFormat = $format_sortie;
1532
+        if (!$destFormat) {
1533
+            spip_log("pas de format pour $image");
1534
+
1535
+            return;
1536
+        }
1537
+
1538
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1539
+        if (!function_exists($fonction_imagecreatefrom)) {
1540
+            return;
1541
+        }
1542
+        $srcImage = @$fonction_imagecreatefrom($image);
1543
+        if (!$srcImage) {
1544
+            spip_log('echec gd1/gd2');
1545
+
1546
+            return;
1547
+        }
1548
+
1549
+        // Initialisation de l'image destination
1550
+        $destImage = null;
1551
+        if ($process == 'gd2' and $destFormat != 'gif') {
1552
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1553
+        }
1554
+        if (!$destImage) {
1555
+            $destImage = ImageCreate($destWidth, $destHeight);
1556
+        }
1557
+
1558
+        // Recopie de l'image d'origine avec adaptation de la taille
1559
+        $ok = false;
1560
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1561
+            if ($format == 'gif') {
1562
+                // Si un GIF est transparent,
1563
+                // fabriquer un PNG transparent
1564
+                $transp = imagecolortransparent($srcImage);
1565
+                if ($transp > 0) {
1566
+                    $destFormat = 'png';
1567
+                }
1568
+            }
1569
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1570
+                // Conserver la transparence
1571
+                if (function_exists('imageAntiAlias')) {
1572
+                    imageAntiAlias($destImage, true);
1573
+                }
1574
+                @imagealphablending($destImage, false);
1575
+                @imagesavealpha($destImage, true);
1576
+            }
1577
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1578
+        }
1579
+        if (!$ok) {
1580
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1581
+        }
1582
+
1583
+        // Sauvegarde de l'image destination
1584
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1585
+        $valeurs['format_dest'] = $format = $destFormat;
1586
+        _image_gd_output($destImage, $valeurs);
1587
+
1588
+        if ($srcImage) {
1589
+            ImageDestroy($srcImage);
1590
+        }
1591
+        ImageDestroy($destImage);
1592
+    }
1593
+
1594
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1595
+        $size = [$destWidth, $destHeight];
1596
+    }
1597
+
1598
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1599
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1600
+    if ($size[0] < 1) {
1601
+        $size[0] = $destWidth;
1602
+    }
1603
+    if ($size[1] < 1) {
1604
+        $size[1] = $destHeight;
1605
+    }
1606
+
1607
+    $retour['width'] = $largeur = $size[0];
1608
+    $retour['height'] = $hauteur = $size[1];
1609
+
1610
+    $retour['fichier'] = $vignette;
1611
+    $retour['format'] = $format;
1612
+    $retour['date'] = @filemtime($vignette);
1613
+
1614
+    // renvoyer l'image
1615
+    return $retour;
1616 1616
 }
1617 1617
 
1618 1618
 /**
@@ -1632,25 +1632,25 @@  discard block
 block discarded – undo
1632 1632
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1633 1633
  **/
1634 1634
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1635
-	$ratioWidth = $srcWidth / $maxWidth;
1636
-	$ratioHeight = $srcHeight / $maxHeight;
1637
-
1638
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1639
-		$destWidth = $srcWidth;
1640
-		$destHeight = $srcHeight;
1641
-	} elseif ($ratioWidth < $ratioHeight) {
1642
-		$destWidth = $srcWidth / $ratioHeight;
1643
-		$destHeight = $maxHeight;
1644
-	} else {
1645
-		$destWidth = $maxWidth;
1646
-		$destHeight = $srcHeight / $ratioWidth;
1647
-	}
1648
-
1649
-	return [
1650
-		intval(round($destWidth)),
1651
-		intval(round($destHeight)),
1652
-		max($ratioWidth, $ratioHeight)
1653
-	];
1635
+    $ratioWidth = $srcWidth / $maxWidth;
1636
+    $ratioHeight = $srcHeight / $maxHeight;
1637
+
1638
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1639
+        $destWidth = $srcWidth;
1640
+        $destHeight = $srcHeight;
1641
+    } elseif ($ratioWidth < $ratioHeight) {
1642
+        $destWidth = $srcWidth / $ratioHeight;
1643
+        $destHeight = $maxHeight;
1644
+    } else {
1645
+        $destWidth = $maxWidth;
1646
+        $destHeight = $srcHeight / $ratioWidth;
1647
+    }
1648
+
1649
+    return [
1650
+        intval(round($destWidth)),
1651
+        intval(round($destHeight)),
1652
+        max($ratioWidth, $ratioHeight)
1653
+    ];
1654 1654
 }
1655 1655
 
1656 1656
 /**
@@ -1670,25 +1670,25 @@  discard block
 block discarded – undo
1670 1670
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1671 1671
  **/
1672 1672
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1673
-	$ratioWidth = $srcWidth / $maxWidth;
1674
-	$ratioHeight = $srcHeight / $maxHeight;
1675
-
1676
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1677
-		$destWidth = $srcWidth;
1678
-		$destHeight = $srcHeight;
1679
-	} elseif ($ratioWidth > $ratioHeight) {
1680
-		$destWidth = $srcWidth / $ratioHeight;
1681
-		$destHeight = $maxHeight;
1682
-	} else {
1683
-		$destWidth = $maxWidth;
1684
-		$destHeight = $srcHeight / $ratioWidth;
1685
-	}
1686
-
1687
-	return [
1688
-		intval(round($destWidth)),
1689
-		intval(round($destHeight)),
1690
-		min($ratioWidth, $ratioHeight)
1691
-	];
1673
+    $ratioWidth = $srcWidth / $maxWidth;
1674
+    $ratioHeight = $srcHeight / $maxHeight;
1675
+
1676
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1677
+        $destWidth = $srcWidth;
1678
+        $destHeight = $srcHeight;
1679
+    } elseif ($ratioWidth > $ratioHeight) {
1680
+        $destWidth = $srcWidth / $ratioHeight;
1681
+        $destHeight = $maxHeight;
1682
+    } else {
1683
+        $destWidth = $maxWidth;
1684
+        $destHeight = $srcHeight / $ratioWidth;
1685
+    }
1686
+
1687
+    return [
1688
+        intval(round($destWidth)),
1689
+        intval(round($destHeight)),
1690
+        min($ratioWidth, $ratioHeight)
1691
+    ];
1692 1692
 }
1693 1693
 
1694 1694
 
@@ -1701,12 +1701,12 @@  discard block
 block discarded – undo
1701 1701
  * @return string
1702 1702
  */
1703 1703
 function process_image_svg_identite($image) {
1704
-	if ($image['creer']) {
1705
-		$source = $image['fichier'];
1706
-		_image_gd_output($source, $image);
1707
-	}
1704
+    if ($image['creer']) {
1705
+        $source = $image['fichier'];
1706
+        _image_gd_output($source, $image);
1707
+    }
1708 1708
 
1709
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1709
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1710 1710
 }
1711 1711
 
1712 1712
 
@@ -1739,109 +1739,109 @@  discard block
 block discarded – undo
1739 1739
  *     Code HTML de la balise img produite
1740 1740
  **/
1741 1741
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1742
-	$image = false;
1743
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1744
-		$process = $GLOBALS['meta']['image_process'];
1745
-	}
1746
-	# determiner le format de sortie
1747
-	$format_sortie = false; // le choix par defaut sera bon
1748
-	if ($process == 'netpbm') {
1749
-		$format_sortie = 'jpg';
1750
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1751
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1752
-		// on verifie que l'extension choisie est bonne (en principe oui)
1753
-		$gd_formats = formats_image_acceptables(true);
1754
-		if (
1755
-			is_array($image)
1756
-			and (!in_array($image['format_dest'], $gd_formats)
1757
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1758
-			)
1759
-		) {
1760
-			if ($image['format_source'] == 'jpg') {
1761
-				$formats_sortie = ['jpg', 'png', 'gif'];
1762
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1763
-			{
1764
-				$formats_sortie = ['png', 'jpg', 'gif'];
1765
-			}
1766
-			// Choisir le format destination
1767
-			// - on sauve de preference en JPEG (meilleure compression)
1768
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1769
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1770
-			# pas *ecrire*
1771
-			$format_sortie = '';
1772
-			foreach ($formats_sortie as $fmt) {
1773
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1774
-					$format_sortie = $fmt;
1775
-					break;
1776
-				}
1777
-			}
1778
-			$image = false;
1779
-		}
1780
-	}
1781
-
1782
-	if (!is_array($image)) {
1783
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1784
-	}
1785
-
1786
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1787
-		spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1788
-		// on peut resizer en mode html si on dispose des elements
1789
-		[$srcw, $srch] = taille_image($img);
1790
-		if ($srcw and $srch) {
1791
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1792
-
1793
-			return _image_tag_changer_taille($img, $w, $h);
1794
-		}
1795
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1796
-		// sous la forme style='max-width: NNpx;'
1797
-		return inserer_attribut(
1798
-			$img,
1799
-			'style',
1800
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1801
-		);
1802
-	}
1803
-
1804
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1805
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1806
-		if ($image['creer']) {
1807
-			@copy($image['fichier'], $image['fichier_dest']);
1808
-		}
1809
-
1810
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1811
-	}
1812
-
1813
-	if ($image['creer'] == false && !$force) {
1814
-		return _image_ecrire_tag(
1815
-			$image,
1816
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1817
-		);
1818
-	}
1819
-
1820
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1821
-		$destWidth = $image['largeur_dest'];
1822
-		$destHeight = $image['hauteur_dest'];
1823
-		$logo = $image['fichier'];
1824
-		$date = $image['date_src'];
1825
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1826
-
1827
-		if ($preview && $preview['fichier']) {
1828
-			$logo = $preview['fichier'];
1829
-			$destWidth = $preview['width'];
1830
-			$destHeight = $preview['height'];
1831
-			$date = $preview['date'];
1832
-		}
1833
-		// dans l'espace prive mettre un timestamp sur l'adresse
1834
-		// de l'image, de facon a tromper le cache du navigateur
1835
-		// quand on fait supprimer/reuploader un logo
1836
-		// (pas de filemtime si SAFE MODE)
1837
-		$date = test_espace_prive() ? ('?' . $date) : '';
1838
-
1839
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1840
-	}
1841
-	else {
1842
-		# BMP, tiff ... les redacteurs osent tout!
1843
-		return $img;
1844
-	}
1742
+    $image = false;
1743
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1744
+        $process = $GLOBALS['meta']['image_process'];
1745
+    }
1746
+    # determiner le format de sortie
1747
+    $format_sortie = false; // le choix par defaut sera bon
1748
+    if ($process == 'netpbm') {
1749
+        $format_sortie = 'jpg';
1750
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1751
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1752
+        // on verifie que l'extension choisie est bonne (en principe oui)
1753
+        $gd_formats = formats_image_acceptables(true);
1754
+        if (
1755
+            is_array($image)
1756
+            and (!in_array($image['format_dest'], $gd_formats)
1757
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1758
+            )
1759
+        ) {
1760
+            if ($image['format_source'] == 'jpg') {
1761
+                $formats_sortie = ['jpg', 'png', 'gif'];
1762
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1763
+            {
1764
+                $formats_sortie = ['png', 'jpg', 'gif'];
1765
+            }
1766
+            // Choisir le format destination
1767
+            // - on sauve de preference en JPEG (meilleure compression)
1768
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1769
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1770
+            # pas *ecrire*
1771
+            $format_sortie = '';
1772
+            foreach ($formats_sortie as $fmt) {
1773
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1774
+                    $format_sortie = $fmt;
1775
+                    break;
1776
+                }
1777
+            }
1778
+            $image = false;
1779
+        }
1780
+    }
1781
+
1782
+    if (!is_array($image)) {
1783
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1784
+    }
1785
+
1786
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1787
+        spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1788
+        // on peut resizer en mode html si on dispose des elements
1789
+        [$srcw, $srch] = taille_image($img);
1790
+        if ($srcw and $srch) {
1791
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1792
+
1793
+            return _image_tag_changer_taille($img, $w, $h);
1794
+        }
1795
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1796
+        // sous la forme style='max-width: NNpx;'
1797
+        return inserer_attribut(
1798
+            $img,
1799
+            'style',
1800
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1801
+        );
1802
+    }
1803
+
1804
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1805
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1806
+        if ($image['creer']) {
1807
+            @copy($image['fichier'], $image['fichier_dest']);
1808
+        }
1809
+
1810
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1811
+    }
1812
+
1813
+    if ($image['creer'] == false && !$force) {
1814
+        return _image_ecrire_tag(
1815
+            $image,
1816
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1817
+        );
1818
+    }
1819
+
1820
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1821
+        $destWidth = $image['largeur_dest'];
1822
+        $destHeight = $image['hauteur_dest'];
1823
+        $logo = $image['fichier'];
1824
+        $date = $image['date_src'];
1825
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1826
+
1827
+        if ($preview && $preview['fichier']) {
1828
+            $logo = $preview['fichier'];
1829
+            $destWidth = $preview['width'];
1830
+            $destHeight = $preview['height'];
1831
+            $date = $preview['date'];
1832
+        }
1833
+        // dans l'espace prive mettre un timestamp sur l'adresse
1834
+        // de l'image, de facon a tromper le cache du navigateur
1835
+        // quand on fait supprimer/reuploader un logo
1836
+        // (pas de filemtime si SAFE MODE)
1837
+        $date = test_espace_prive() ? ('?' . $date) : '';
1838
+
1839
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1840
+    }
1841
+    else {
1842
+        # BMP, tiff ... les redacteurs osent tout!
1843
+        return $img;
1844
+    }
1845 1845
 }
1846 1846
 
1847 1847
 /**
@@ -1855,145 +1855,145 @@  discard block
 block discarded – undo
1855 1855
  * Class phpthumb_functions
1856 1856
  */
1857 1857
 class phpthumb_functions {
1858
-	/**
1859
-	 * Retourne la couleur d'un pixel dans une image
1860
-	 *
1861
-	 * @param resource|GdImage $img
1862
-	 * @param int $x
1863
-	 * @param int $y
1864
-	 * @return array|bool
1865
-	 */
1866
-	public static function GetPixelColor(&$img, $x, $y) {
1867
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1868
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1869
-		}
1870
-		return false;
1871
-	}
1872
-
1873
-	/**
1874
-	 * Retourne un nombre dans une représentation en Little Endian
1875
-	 *
1876
-	 * @param int $number
1877
-	 * @param int $minbytes
1878
-	 * @return string
1879
-	 */
1880
-	public static function LittleEndian2String($number, $minbytes = 1) {
1881
-		$intstring = '';
1882
-		while ($number > 0) {
1883
-			$intstring = $intstring . chr($number & 255);
1884
-			$number >>= 8;
1885
-		}
1886
-
1887
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1888
-	}
1889
-
1890
-	/**
1891
-	 * Transforme une ressource GD en image au format ICO
1892
-	 *
1893
-	 * @param array $gd_image_array
1894
-	 *     Tableau de ressources d'images GD
1895
-	 * @return string
1896
-	 *     Image au format ICO
1897
-	 */
1898
-	public static function GD2ICOstring(&$gd_image_array) {
1899
-		foreach ($gd_image_array as $key => $gd_image) {
1900
-			$ImageWidths[$key] = ImageSX($gd_image);
1901
-			$ImageHeights[$key] = ImageSY($gd_image);
1902
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1903
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1904
-
1905
-			$icXOR[$key] = '';
1906
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1907
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1908
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1909
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1910
-					$r = $argb['red'];
1911
-					$g = $argb['green'];
1912
-					$b = $argb['blue'];
1913
-
1914
-					if ($bpp[$key] == 32) {
1915
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1916
-					} elseif ($bpp[$key] == 24) {
1917
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1918
-					}
1919
-
1920
-					if ($a < 128) {
1921
-						@$icANDmask[$key][$y] .= '1';
1922
-					} else {
1923
-						@$icANDmask[$key][$y] .= '0';
1924
-					}
1925
-				}
1926
-				// mask bits are 32-bit aligned per scanline
1927
-				while (strlen($icANDmask[$key][$y]) % 32) {
1928
-					$icANDmask[$key][$y] .= '0';
1929
-				}
1930
-			}
1931
-			$icAND[$key] = '';
1932
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1933
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1934
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1935
-				}
1936
-			}
1937
-		}
1938
-
1939
-		foreach ($gd_image_array as $key => $gd_image) {
1940
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1941
-
1942
-			// BITMAPINFOHEADER - 40 bytes
1943
-			$BitmapInfoHeader[$key] = '';
1944
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1945
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1946
-			// The biHeight member specifies the combined
1947
-			// height of the XOR and AND masks.
1948
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1949
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1950
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1951
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1952
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1953
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1954
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1955
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1956
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1957
-		}
1958
-
1959
-
1960
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1961
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1962
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1963
-
1964
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1965
-		foreach ($gd_image_array as $key => $gd_image) {
1966
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1967
-
1968
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1969
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1970
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1971
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1972
-
1973
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1974
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1975
-
1976
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1977
-			$icondata .= phpthumb_functions::LittleEndian2String(
1978
-				$dwBytesInRes,
1979
-				4
1980
-			);     // dwBytesInRes;	// How many bytes in this resource?
1981
-
1982
-			$icondata .= phpthumb_functions::LittleEndian2String(
1983
-				$dwImageOffset,
1984
-				4
1985
-			);    // dwImageOffset;   // Where in the file is this image?
1986
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1987
-			$dwImageOffset += strlen($icXOR[$key]);
1988
-			$dwImageOffset += strlen($icAND[$key]);
1989
-		}
1990
-
1991
-		foreach ($gd_image_array as $key => $gd_image) {
1992
-			$icondata .= $BitmapInfoHeader[$key];
1993
-			$icondata .= $icXOR[$key];
1994
-			$icondata .= $icAND[$key];
1995
-		}
1996
-
1997
-		return $icondata;
1998
-	}
1858
+    /**
1859
+     * Retourne la couleur d'un pixel dans une image
1860
+     *
1861
+     * @param resource|GdImage $img
1862
+     * @param int $x
1863
+     * @param int $y
1864
+     * @return array|bool
1865
+     */
1866
+    public static function GetPixelColor(&$img, $x, $y) {
1867
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1868
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1869
+        }
1870
+        return false;
1871
+    }
1872
+
1873
+    /**
1874
+     * Retourne un nombre dans une représentation en Little Endian
1875
+     *
1876
+     * @param int $number
1877
+     * @param int $minbytes
1878
+     * @return string
1879
+     */
1880
+    public static function LittleEndian2String($number, $minbytes = 1) {
1881
+        $intstring = '';
1882
+        while ($number > 0) {
1883
+            $intstring = $intstring . chr($number & 255);
1884
+            $number >>= 8;
1885
+        }
1886
+
1887
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1888
+    }
1889
+
1890
+    /**
1891
+     * Transforme une ressource GD en image au format ICO
1892
+     *
1893
+     * @param array $gd_image_array
1894
+     *     Tableau de ressources d'images GD
1895
+     * @return string
1896
+     *     Image au format ICO
1897
+     */
1898
+    public static function GD2ICOstring(&$gd_image_array) {
1899
+        foreach ($gd_image_array as $key => $gd_image) {
1900
+            $ImageWidths[$key] = ImageSX($gd_image);
1901
+            $ImageHeights[$key] = ImageSY($gd_image);
1902
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1903
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1904
+
1905
+            $icXOR[$key] = '';
1906
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1907
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1908
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1909
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1910
+                    $r = $argb['red'];
1911
+                    $g = $argb['green'];
1912
+                    $b = $argb['blue'];
1913
+
1914
+                    if ($bpp[$key] == 32) {
1915
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1916
+                    } elseif ($bpp[$key] == 24) {
1917
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1918
+                    }
1919
+
1920
+                    if ($a < 128) {
1921
+                        @$icANDmask[$key][$y] .= '1';
1922
+                    } else {
1923
+                        @$icANDmask[$key][$y] .= '0';
1924
+                    }
1925
+                }
1926
+                // mask bits are 32-bit aligned per scanline
1927
+                while (strlen($icANDmask[$key][$y]) % 32) {
1928
+                    $icANDmask[$key][$y] .= '0';
1929
+                }
1930
+            }
1931
+            $icAND[$key] = '';
1932
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1933
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1934
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1935
+                }
1936
+            }
1937
+        }
1938
+
1939
+        foreach ($gd_image_array as $key => $gd_image) {
1940
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1941
+
1942
+            // BITMAPINFOHEADER - 40 bytes
1943
+            $BitmapInfoHeader[$key] = '';
1944
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1945
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1946
+            // The biHeight member specifies the combined
1947
+            // height of the XOR and AND masks.
1948
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1949
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1950
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1951
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1952
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1953
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1954
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1955
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1956
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1957
+        }
1958
+
1959
+
1960
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1961
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1962
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1963
+
1964
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1965
+        foreach ($gd_image_array as $key => $gd_image) {
1966
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1967
+
1968
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1969
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1970
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1971
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1972
+
1973
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1974
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1975
+
1976
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1977
+            $icondata .= phpthumb_functions::LittleEndian2String(
1978
+                $dwBytesInRes,
1979
+                4
1980
+            );     // dwBytesInRes;	// How many bytes in this resource?
1981
+
1982
+            $icondata .= phpthumb_functions::LittleEndian2String(
1983
+                $dwImageOffset,
1984
+                4
1985
+            );    // dwImageOffset;   // Where in the file is this image?
1986
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1987
+            $dwImageOffset += strlen($icXOR[$key]);
1988
+            $dwImageOffset += strlen($icAND[$key]);
1989
+        }
1990
+
1991
+        foreach ($gd_image_array as $key => $gd_image) {
1992
+            $icondata .= $BitmapInfoHeader[$key];
1993
+            $icondata .= $icXOR[$key];
1994
+            $icondata .= $icAND[$key];
1995
+        }
1996
+
1997
+        return $icondata;
1998
+    }
1999 1999
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
 	$blue = dechex($blue);
44 44
 
45 45
 	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
46
+		$red = '0'.$red;
47 47
 	}
48 48
 	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
49
+		$green = '0'.$green;
50 50
 	}
51 51
 	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
52
+		$blue = '0'.$blue;
53 53
 	}
54 54
 
55 55
 	return "$red$green$blue";
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	$couleur = couleur_html_to_hex($couleur);
69 69
 	$couleur = ltrim($couleur, '#');
70 70
 	if (strlen($couleur) === 3) {
71
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
71
+		$couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2];
72 72
 	}
73 73
 	$retour = [];
74 74
 	$retour['red'] = hexdec(substr($couleur, 0, 2));
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 	$var_G = ($G / 255);
127 127
 	$var_B = ($B / 255);
128 128
 
129
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
129
+	$var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB
130
+	$var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB
131
+	$del_Max = $var_Max - $var_Min; //Delta RGB value
132 132
 
133 133
 	$L = ($var_Max + $var_Min) / 2;
134 134
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
  */
191 191
 function _couleur_hsl_to_rgb($H, $S, $L) {
192 192
 	// helper
193
-	$hue_2_rgb = function ($v1, $v2, $vH) {
193
+	$hue_2_rgb = function($v1, $v2, $vH) {
194 194
 		if ($vH < 0) {
195 195
 			$vH += 1;
196 196
 		}
@@ -322,11 +322,11 @@  discard block
 block discarded – undo
322 322
 		$img = "<img src='$source' />";
323 323
 	} elseif (
324 324
 		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
325
+		and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])
326 326
 		and in_array($extension, _image_extensions_acceptees_en_entree())
327 327
 	) {
328 328
 		# gerer img src="data:....base64"
329
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
329
+		$local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension);
330 330
 		if (!file_exists($local)) {
331 331
 			ecrire_fichier($local, base64_decode($regs[2]));
332 332
 		}
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 	// les protocoles web prennent au moins 3 lettres
344 344
 	if (tester_url_absolue($source)) {
345 345
 		include_spip('inc/distant');
346
-		$fichier = _DIR_RACINE . copie_locale($source);
346
+		$fichier = _DIR_RACINE.copie_locale($source);
347 347
 		if (!$fichier) {
348 348
 			return '';
349 349
 		}
@@ -445,9 +445,9 @@  discard block
 block discarded – undo
445 445
 			// on garde la terminaison initiale car image simplement copiee
446 446
 			// et on postfixe son nom avec un md5 du path
447 447
 			$terminaison_dest = $terminaison;
448
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
448
+			$fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5);
449 449
 		} else {
450
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
450
+			$fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5);
451 451
 		}
452 452
 		$cache = sous_repertoire(_DIR_VAR, $cache);
453 453
 		$cache = sous_repertoire($cache, $effet);
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 		$fichier_dest = substr($fichier_dest, 2);
459 459
 	}
460 460
 
461
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
461
+	$fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest;
462 462
 
463 463
 	$GLOBALS['images_calculees'][] = $fichier_dest;
464 464
 
@@ -496,15 +496,15 @@  discard block
 block discarded – undo
496 496
 
497 497
 	if ($creer) {
498 498
 		spip_log(
499
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
500
-			'images' . _LOG_DEBUG
499
+			'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier",
500
+			'images'._LOG_DEBUG
501 501
 		);
502 502
 	}
503 503
 
504 504
 	$term_fonction = _image_trouver_extension_pertinente($fichier);
505
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
505
+	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction;
506 506
 	$ret['fichier'] = $fichier;
507
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
507
+	$ret['fonction_image'] = '_image_image'.$terminaison_dest;
508 508
 	$ret['fichier_dest'] = $fichier_dest;
509 509
 	$ret['format_source'] = _image_extension_normalisee($terminaison);
510 510
 	$ret['format_dest'] = $terminaison_dest;
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 
655 655
 	$_terminaison = _image_trouver_extension_depuis_mime($mime);
656 656
 	if ($_terminaison and $_terminaison !== $terminaison) {
657
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
657
+		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE);
658 658
 		$terminaison = $_terminaison;
659 659
 	}
660 660
 	return $terminaison;
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
 	if (!function_exists('imagepng')) {
812 812
 		return false;
813 813
 	}
814
-	$tmp = $fichier . '.tmp';
814
+	$tmp = $fichier.'.tmp';
815 815
 	$ret = imagepng($img, $tmp);
816 816
 	if (file_exists($tmp)) {
817 817
 		$taille_test = @getimagesize($tmp);
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 	if (!function_exists('imagegif')) {
847 847
 		return false;
848 848
 	}
849
-	$tmp = $fichier . '.tmp';
849
+	$tmp = $fichier.'.tmp';
850 850
 	$ret = imagegif($img, $tmp);
851 851
 	if (file_exists($tmp)) {
852 852
 		$taille_test = @getimagesize($tmp);
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 	if (!function_exists('imagejpeg')) {
887 887
 		return false;
888 888
 	}
889
-	$tmp = $fichier . '.tmp';
889
+	$tmp = $fichier.'.tmp';
890 890
 
891 891
 	// Enable interlancing
892 892
 	imageinterlace($img, true);
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 	if (!function_exists('imagewebp')) {
948 948
 		return false;
949 949
 	}
950
-	$tmp = $fichier . '.tmp';
950
+	$tmp = $fichier.'.tmp';
951 951
 	$ret = imagewebp($img, $tmp, $qualite);
952 952
 	if (file_exists($tmp)) {
953 953
 		$taille_test = @getimagesize($tmp);
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
  */
982 982
 function _image_imagesvg($img, $fichier) {
983 983
 
984
-	$tmp = $fichier . '.tmp';
984
+	$tmp = $fichier.'.tmp';
985 985
 	if (strpos($img, '<') === false) {
986 986
 		$img = supprimer_timestamp($img);
987 987
 		if (!file_exists($img)) {
@@ -1038,13 +1038,13 @@  discard block
 block discarded – undo
1038 1038
  */
1039 1039
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1040 1040
 	if (is_null($fonction)) {
1041
-		$fonction = '_image_image' . $valeurs['format_dest'];
1041
+		$fonction = '_image_image'.$valeurs['format_dest'];
1042 1042
 	}
1043 1043
 	$ret = false;
1044 1044
 	#un flag pour reperer les images gravees
1045 1045
 	$lock = (
1046 1046
 		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1047
-		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1047
+		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src'))
1048 1048
 	);
1049 1049
 	if (
1050 1050
 		function_exists($fonction)
@@ -1056,7 +1056,7 @@  discard block
 block discarded – undo
1056 1056
 			// dans tous les cas mettre a jour la taille de l'image finale
1057 1057
 			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1058 1058
 			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1059
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1059
+			ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true);
1060 1060
 		}
1061 1061
 	}
1062 1062
 
@@ -1231,7 +1231,7 @@  discard block
 block discarded – undo
1231 1231
 
1232 1232
 	// attributs deprecies. Transformer en CSS
1233 1233
 	if ($espace = extraire_attribut($tag, 'hspace')) {
1234
-		$style = "margin:{$espace}px;" . $style;
1234
+		$style = "margin:{$espace}px;".$style;
1235 1235
 		$tag = inserer_attribut($tag, 'hspace', '');
1236 1236
 	}
1237 1237
 
@@ -1358,7 +1358,7 @@  discard block
 block discarded – undo
1358 1358
 	$image = $valeurs['fichier'];
1359 1359
 	$format = $valeurs['format_source'];
1360 1360
 	$destdir = dirname($valeurs['fichier_dest']);
1361
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1361
+	$destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']);
1362 1362
 
1363 1363
 	$format_sortie = $valeurs['format_dest'];
1364 1364
 
@@ -1390,7 +1390,7 @@  discard block
 block discarded – undo
1390 1390
 
1391 1391
 	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1392 1392
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1393
-		$vignette = $destination . '.' . $format;
1393
+		$vignette = $destination.'.'.$format;
1394 1394
 		@copy($image, $vignette);
1395 1395
 	}
1396 1396
 
@@ -1398,7 +1398,7 @@  discard block
 block discarded – undo
1398 1398
 		include_spip('inc/svg');
1399 1399
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1400 1400
 			$format_sortie = 'svg';
1401
-			$vignette = $destination . '.' . $format_sortie;
1401
+			$vignette = $destination.'.'.$format_sortie;
1402 1402
 			$valeurs['fichier_dest'] = $vignette;
1403 1403
 			_image_gd_output($svg, $valeurs);
1404 1404
 		}
@@ -1410,9 +1410,9 @@  discard block
 block discarded – undo
1410 1410
 			define('_CONVERT_COMMAND', 'convert');
1411 1411
 		} // Securite : mes_options.php peut preciser le chemin absolu
1412 1412
 		if (!defined('_RESIZE_COMMAND')) {
1413
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1413
+			define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest');
1414 1414
 		}
1415
-		$vignette = $destination . '.' . $format_sortie;
1415
+		$vignette = $destination.'.'.$format_sortie;
1416 1416
 		$commande = str_replace(
1417 1417
 			['%x', '%y', '%src', '%dest'],
1418 1418
 			[
@@ -1428,7 +1428,7 @@  discard block
 block discarded – undo
1428 1428
 		if (!@file_exists($vignette)) {
1429 1429
 			spip_log("echec convert sur $vignette");
1430 1430
 
1431
-			return;  // echec commande
1431
+			return; // echec commande
1432 1432
 		}
1433 1433
 	}
1434 1434
 
@@ -1445,7 +1445,7 @@  discard block
 block discarded – undo
1445 1445
 		if (!$output) {
1446 1446
 			return;
1447 1447
 		}
1448
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1448
+		$vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie;
1449 1449
 
1450 1450
 		$imagick = new Imagick();
1451 1451
 		$imagick->readImage(realpath($image));
@@ -1454,7 +1454,7 @@  discard block
 block discarded – undo
1454 1454
 			$destHeight,
1455 1455
 			Imagick::FILTER_LANCZOS,
1456 1456
 			1
1457
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1457
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1458 1458
 		$imagick->writeImage($vignette);
1459 1459
 
1460 1460
 		if (!@file_exists($vignette)) {
@@ -1463,7 +1463,7 @@  discard block
 block discarded – undo
1463 1463
 			return;
1464 1464
 		}
1465 1465
 		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1466
-		$vignette = $destination . '.' . $format_sortie;
1466
+		$vignette = $destination.'.'.$format_sortie;
1467 1467
 	}
1468 1468
 
1469 1469
 	// netpbm
@@ -1474,11 +1474,11 @@  discard block
 block discarded – undo
1474 1474
 		if (_PNMSCALE_COMMAND == '') {
1475 1475
 			return;
1476 1476
 		}
1477
-		$vignette = $destination . '.' . $format_sortie;
1477
+		$vignette = $destination.'.'.$format_sortie;
1478 1478
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1479 1479
 		if ($format == 'jpg') {
1480 1480
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1481
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1481
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1482 1482
 			if (!($s = @filesize($vignette))) {
1483 1483
 				spip_unlink($vignette);
1484 1484
 			}
@@ -1490,7 +1490,7 @@  discard block
 block discarded – undo
1490 1490
 		} else {
1491 1491
 			if ($format == 'gif') {
1492 1492
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1493
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1493
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1494 1494
 				if (!($s = @filesize($vignette))) {
1495 1495
 					spip_unlink($vignette);
1496 1496
 				}
@@ -1502,7 +1502,7 @@  discard block
 block discarded – undo
1502 1502
 			} else {
1503 1503
 				if ($format == 'png') {
1504 1504
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1505
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1506 1506
 					if (!($s = @filesize($vignette))) {
1507 1507
 						spip_unlink($vignette);
1508 1508
 					}
@@ -1524,7 +1524,7 @@  discard block
 block discarded – undo
1524 1524
 			return;
1525 1525
 		}
1526 1526
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1527
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1527
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1528 1528
 
1529 1529
 			return;
1530 1530
 		}
@@ -1834,7 +1834,7 @@  discard block
 block discarded – undo
1834 1834
 		// de l'image, de facon a tromper le cache du navigateur
1835 1835
 		// quand on fait supprimer/reuploader un logo
1836 1836
 		// (pas de filemtime si SAFE MODE)
1837
-		$date = test_espace_prive() ? ('?' . $date) : '';
1837
+		$date = test_espace_prive() ? ('?'.$date) : '';
1838 1838
 
1839 1839
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1840 1840
 	}
@@ -1880,7 +1880,7 @@  discard block
 block discarded – undo
1880 1880
 	public static function LittleEndian2String($number, $minbytes = 1) {
1881 1881
 		$intstring = '';
1882 1882
 		while ($number > 0) {
1883
-			$intstring = $intstring . chr($number & 255);
1883
+			$intstring = $intstring.chr($number & 255);
1884 1884
 			$number >>= 8;
1885 1885
 		}
1886 1886
 
@@ -1912,9 +1912,9 @@  discard block
 block discarded – undo
1912 1912
 					$b = $argb['blue'];
1913 1913
 
1914 1914
 					if ($bpp[$key] == 32) {
1915
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1915
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1916 1916
 					} elseif ($bpp[$key] == 24) {
1917
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1917
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1918 1918
 					}
1919 1919
 
1920 1920
 					if ($a < 128) {
@@ -1941,48 +1941,48 @@  discard block
 block discarded – undo
1941 1941
 
1942 1942
 			// BITMAPINFOHEADER - 40 bytes
1943 1943
 			$BitmapInfoHeader[$key] = '';
1944
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1945
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1944
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1945
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1946 1946
 			// The biHeight member specifies the combined
1947 1947
 			// height of the XOR and AND masks.
1948 1948
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1949
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1950
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1951
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1952
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1953
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1954
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1955
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1956
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1949
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1950
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1951
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1952
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1953
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1954
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1955
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1956
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1957 1957
 		}
1958 1958
 
1959 1959
 
1960
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1961
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1962
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1960
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1961
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1962
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1963 1963
 
1964 1964
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1965 1965
 		foreach ($gd_image_array as $key => $gd_image) {
1966 1966
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1967 1967
 
1968
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1969
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1970
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1971
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1968
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1969
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1970
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1971
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1972 1972
 
1973
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1974
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1973
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1974
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1975 1975
 
1976 1976
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1977 1977
 			$icondata .= phpthumb_functions::LittleEndian2String(
1978 1978
 				$dwBytesInRes,
1979 1979
 				4
1980
-			);     // dwBytesInRes;	// How many bytes in this resource?
1980
+			); // dwBytesInRes;	// How many bytes in this resource?
1981 1981
 
1982 1982
 			$icondata .= phpthumb_functions::LittleEndian2String(
1983 1983
 				$dwImageOffset,
1984 1984
 				4
1985
-			);    // dwImageOffset;   // Where in the file is this image?
1985
+			); // dwImageOffset;   // Where in the file is this image?
1986 1986
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1987 1987
 			$dwImageOffset += strlen($icXOR[$key]);
1988 1988
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.
Braces   +4 added lines, -9 removed lines patch added patch discarded remove patch
@@ -542,8 +542,7 @@  discard block
 block discarded – undo
542 542
 			process_image_svg_identite($ret);
543 543
 			$ret['creer'] = false;
544 544
 		}
545
-	}
546
-	else {
545
+	} else {
547 546
 		if (!function_exists($ret['fonction_imagecreatefrom'])) {
548 547
 			return false;
549 548
 		}
@@ -647,8 +646,7 @@  discard block
 block discarded – undo
647 646
 
648 647
 	if (isset($info['mime'])) {
649 648
 		$mime = $info['mime'];
650
-	}
651
-	else {
649
+	} else {
652 650
 		$mime = image_type_to_mime_type($info[2]);
653 651
 	}
654 652
 
@@ -1392,9 +1390,7 @@  discard block
 block discarded – undo
1392 1390
 	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1393 1391
 		$vignette = $destination . '.' . $format;
1394 1392
 		@copy($image, $vignette);
1395
-	}
1396
-
1397
-	elseif ($valeurs['format_source'] === 'svg') {
1393
+	} elseif ($valeurs['format_source'] === 'svg') {
1398 1394
 		include_spip('inc/svg');
1399 1395
 		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1400 1396
 			$format_sortie = 'svg';
@@ -1837,8 +1833,7 @@  discard block
 block discarded – undo
1837 1833
 		$date = test_espace_prive() ? ('?' . $date) : '';
1838 1834
 
1839 1835
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1840
-	}
1841
-	else {
1836
+	} else {
1842 1837
 		# BMP, tiff ... les redacteurs osent tout!
1843 1838
 		return $img;
1844 1839
 	}
Please login to merge, or discard this patch.