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