Completed
Push — master ( 39a0b7...d9bd2d )
by cam
01:03
created
ecrire/inc/filtres_images_lib_mini.php 2 patches
Indentation   +1315 added lines, -1315 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,259 +1344,259 @@  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
-		$vignette = "$destination." . $format_sortie;
1430
-
1431
-		if (!class_exists(\Imagick::class)) {
1432
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1433
-
1434
-			return;
1435
-		}
1436
-		$imagick = new Imagick();
1437
-		$imagick->readImage(realpath($image));
1438
-		$imagick->resizeImage(
1439
-			$destWidth,
1440
-			$destHeight,
1441
-			Imagick::FILTER_LANCZOS,
1442
-			1
1443
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1444
-		$imagick->writeImage(realpath($vignette));
1445
-
1446
-		if (!@file_exists($vignette)) {
1447
-			spip_log("echec imagick sur $vignette");
1448
-
1449
-			return;
1450
-		}
1451
-	}
1452
-
1453
-	// netpbm
1454
-	elseif ($process == 'netpbm') {
1455
-		if (!defined('_PNMSCALE_COMMAND')) {
1456
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1457
-		} // Securite : mes_options.php peut preciser le chemin absolu
1458
-		if (_PNMSCALE_COMMAND == '') {
1459
-			return;
1460
-		}
1461
-		$vignette = $destination . '.' . $format_sortie;
1462
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1463
-		if ($format == 'jpg') {
1464
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1465
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1466
-			if (!($s = @filesize($vignette))) {
1467
-				spip_unlink($vignette);
1468
-			}
1469
-			if (!@file_exists($vignette)) {
1470
-				spip_log("echec netpbm-jpg sur $vignette");
1471
-
1472
-				return;
1473
-			}
1474
-		} else {
1475
-			if ($format == 'gif') {
1476
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1477
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1478
-				if (!($s = @filesize($vignette))) {
1479
-					spip_unlink($vignette);
1480
-				}
1481
-				if (!@file_exists($vignette)) {
1482
-					spip_log("echec netpbm-gif sur $vignette");
1483
-
1484
-					return;
1485
-				}
1486
-			} else {
1487
-				if ($format == 'png') {
1488
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1489
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1490
-					if (!($s = @filesize($vignette))) {
1491
-						spip_unlink($vignette);
1492
-					}
1493
-					if (!@file_exists($vignette)) {
1494
-						spip_log("echec netpbm-png sur $vignette");
1495
-
1496
-						return;
1497
-					}
1498
-				}
1499
-			}
1500
-		}
1501
-	}
1502
-
1503
-	// gd ou gd2
1504
-	elseif ($process == 'gd1' or $process == 'gd2') {
1505
-		if (!function_exists('gd_info')) {
1506
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1507
-
1508
-			return;
1509
-		}
1510
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1511
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1512
-
1513
-			return;
1514
-		}
1515
-		$destFormat = $format_sortie;
1516
-		if (!$destFormat) {
1517
-			spip_log("pas de format pour $image");
1518
-
1519
-			return;
1520
-		}
1521
-
1522
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1523
-		if (!function_exists($fonction_imagecreatefrom)) {
1524
-			return;
1525
-		}
1526
-		$srcImage = @$fonction_imagecreatefrom($image);
1527
-		if (!$srcImage) {
1528
-			spip_log('echec gd1/gd2');
1529
-
1530
-			return;
1531
-		}
1532
-
1533
-		// Initialisation de l'image destination
1534
-		$destImage = null;
1535
-		if ($process == 'gd2' and $destFormat != 'gif') {
1536
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1537
-		}
1538
-		if (!$destImage) {
1539
-			$destImage = ImageCreate($destWidth, $destHeight);
1540
-		}
1541
-
1542
-		// Recopie de l'image d'origine avec adaptation de la taille
1543
-		$ok = false;
1544
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1545
-			if ($format == 'gif') {
1546
-				// Si un GIF est transparent,
1547
-				// fabriquer un PNG transparent
1548
-				$transp = imagecolortransparent($srcImage);
1549
-				if ($transp > 0) {
1550
-					$destFormat = 'png';
1551
-				}
1552
-			}
1553
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1554
-				// Conserver la transparence
1555
-				if (function_exists('imageAntiAlias')) {
1556
-					imageAntiAlias($destImage, true);
1557
-				}
1558
-				@imagealphablending($destImage, false);
1559
-				@imagesavealpha($destImage, true);
1560
-			}
1561
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1562
-		}
1563
-		if (!$ok) {
1564
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1565
-		}
1566
-
1567
-		// Sauvegarde de l'image destination
1568
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1569
-		$valeurs['format_dest'] = $format = $destFormat;
1570
-		_image_gd_output($destImage, $valeurs);
1571
-
1572
-		if ($srcImage) {
1573
-			ImageDestroy($srcImage);
1574
-		}
1575
-		ImageDestroy($destImage);
1576
-	}
1577
-
1578
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1579
-		$size = [$destWidth, $destHeight];
1580
-	}
1581
-
1582
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1583
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1584
-	if ($size[0] < 1) {
1585
-		$size[0] = $destWidth;
1586
-	}
1587
-	if ($size[1] < 1) {
1588
-		$size[1] = $destHeight;
1589
-	}
1590
-
1591
-	$retour['width'] = $largeur = $size[0];
1592
-	$retour['height'] = $hauteur = $size[1];
1593
-
1594
-	$retour['fichier'] = $vignette;
1595
-	$retour['format'] = $format;
1596
-	$retour['date'] = @filemtime($vignette);
1597
-
1598
-	// renvoyer l'image
1599
-	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
+        $vignette = "$destination." . $format_sortie;
1430
+
1431
+        if (!class_exists(\Imagick::class)) {
1432
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1433
+
1434
+            return;
1435
+        }
1436
+        $imagick = new Imagick();
1437
+        $imagick->readImage(realpath($image));
1438
+        $imagick->resizeImage(
1439
+            $destWidth,
1440
+            $destHeight,
1441
+            Imagick::FILTER_LANCZOS,
1442
+            1
1443
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1444
+        $imagick->writeImage(realpath($vignette));
1445
+
1446
+        if (!@file_exists($vignette)) {
1447
+            spip_log("echec imagick sur $vignette");
1448
+
1449
+            return;
1450
+        }
1451
+    }
1452
+
1453
+    // netpbm
1454
+    elseif ($process == 'netpbm') {
1455
+        if (!defined('_PNMSCALE_COMMAND')) {
1456
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1457
+        } // Securite : mes_options.php peut preciser le chemin absolu
1458
+        if (_PNMSCALE_COMMAND == '') {
1459
+            return;
1460
+        }
1461
+        $vignette = $destination . '.' . $format_sortie;
1462
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1463
+        if ($format == 'jpg') {
1464
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1465
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1466
+            if (!($s = @filesize($vignette))) {
1467
+                spip_unlink($vignette);
1468
+            }
1469
+            if (!@file_exists($vignette)) {
1470
+                spip_log("echec netpbm-jpg sur $vignette");
1471
+
1472
+                return;
1473
+            }
1474
+        } else {
1475
+            if ($format == 'gif') {
1476
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1477
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1478
+                if (!($s = @filesize($vignette))) {
1479
+                    spip_unlink($vignette);
1480
+                }
1481
+                if (!@file_exists($vignette)) {
1482
+                    spip_log("echec netpbm-gif sur $vignette");
1483
+
1484
+                    return;
1485
+                }
1486
+            } else {
1487
+                if ($format == 'png') {
1488
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1489
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1490
+                    if (!($s = @filesize($vignette))) {
1491
+                        spip_unlink($vignette);
1492
+                    }
1493
+                    if (!@file_exists($vignette)) {
1494
+                        spip_log("echec netpbm-png sur $vignette");
1495
+
1496
+                        return;
1497
+                    }
1498
+                }
1499
+            }
1500
+        }
1501
+    }
1502
+
1503
+    // gd ou gd2
1504
+    elseif ($process == 'gd1' or $process == 'gd2') {
1505
+        if (!function_exists('gd_info')) {
1506
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1507
+
1508
+            return;
1509
+        }
1510
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1511
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1512
+
1513
+            return;
1514
+        }
1515
+        $destFormat = $format_sortie;
1516
+        if (!$destFormat) {
1517
+            spip_log("pas de format pour $image");
1518
+
1519
+            return;
1520
+        }
1521
+
1522
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1523
+        if (!function_exists($fonction_imagecreatefrom)) {
1524
+            return;
1525
+        }
1526
+        $srcImage = @$fonction_imagecreatefrom($image);
1527
+        if (!$srcImage) {
1528
+            spip_log('echec gd1/gd2');
1529
+
1530
+            return;
1531
+        }
1532
+
1533
+        // Initialisation de l'image destination
1534
+        $destImage = null;
1535
+        if ($process == 'gd2' and $destFormat != 'gif') {
1536
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1537
+        }
1538
+        if (!$destImage) {
1539
+            $destImage = ImageCreate($destWidth, $destHeight);
1540
+        }
1541
+
1542
+        // Recopie de l'image d'origine avec adaptation de la taille
1543
+        $ok = false;
1544
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1545
+            if ($format == 'gif') {
1546
+                // Si un GIF est transparent,
1547
+                // fabriquer un PNG transparent
1548
+                $transp = imagecolortransparent($srcImage);
1549
+                if ($transp > 0) {
1550
+                    $destFormat = 'png';
1551
+                }
1552
+            }
1553
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1554
+                // Conserver la transparence
1555
+                if (function_exists('imageAntiAlias')) {
1556
+                    imageAntiAlias($destImage, true);
1557
+                }
1558
+                @imagealphablending($destImage, false);
1559
+                @imagesavealpha($destImage, true);
1560
+            }
1561
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1562
+        }
1563
+        if (!$ok) {
1564
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1565
+        }
1566
+
1567
+        // Sauvegarde de l'image destination
1568
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1569
+        $valeurs['format_dest'] = $format = $destFormat;
1570
+        _image_gd_output($destImage, $valeurs);
1571
+
1572
+        if ($srcImage) {
1573
+            ImageDestroy($srcImage);
1574
+        }
1575
+        ImageDestroy($destImage);
1576
+    }
1577
+
1578
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1579
+        $size = [$destWidth, $destHeight];
1580
+    }
1581
+
1582
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1583
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1584
+    if ($size[0] < 1) {
1585
+        $size[0] = $destWidth;
1586
+    }
1587
+    if ($size[1] < 1) {
1588
+        $size[1] = $destHeight;
1589
+    }
1590
+
1591
+    $retour['width'] = $largeur = $size[0];
1592
+    $retour['height'] = $hauteur = $size[1];
1593
+
1594
+    $retour['fichier'] = $vignette;
1595
+    $retour['format'] = $format;
1596
+    $retour['date'] = @filemtime($vignette);
1597
+
1598
+    // renvoyer l'image
1599
+    return $retour;
1600 1600
 }
1601 1601
 
1602 1602
 /**
@@ -1616,25 +1616,25 @@  discard block
 block discarded – undo
1616 1616
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1617 1617
  **/
1618 1618
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1619
-	$ratioWidth = $srcWidth / $maxWidth;
1620
-	$ratioHeight = $srcHeight / $maxHeight;
1621
-
1622
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1623
-		$destWidth = $srcWidth;
1624
-		$destHeight = $srcHeight;
1625
-	} elseif ($ratioWidth < $ratioHeight) {
1626
-		$destWidth = $srcWidth / $ratioHeight;
1627
-		$destHeight = $maxHeight;
1628
-	} else {
1629
-		$destWidth = $maxWidth;
1630
-		$destHeight = $srcHeight / $ratioWidth;
1631
-	}
1632
-
1633
-	return [
1634
-		intval(round($destWidth)),
1635
-		intval(round($destHeight)),
1636
-		max($ratioWidth, $ratioHeight)
1637
-	];
1619
+    $ratioWidth = $srcWidth / $maxWidth;
1620
+    $ratioHeight = $srcHeight / $maxHeight;
1621
+
1622
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1623
+        $destWidth = $srcWidth;
1624
+        $destHeight = $srcHeight;
1625
+    } elseif ($ratioWidth < $ratioHeight) {
1626
+        $destWidth = $srcWidth / $ratioHeight;
1627
+        $destHeight = $maxHeight;
1628
+    } else {
1629
+        $destWidth = $maxWidth;
1630
+        $destHeight = $srcHeight / $ratioWidth;
1631
+    }
1632
+
1633
+    return [
1634
+        intval(round($destWidth)),
1635
+        intval(round($destHeight)),
1636
+        max($ratioWidth, $ratioHeight)
1637
+    ];
1638 1638
 }
1639 1639
 
1640 1640
 /**
@@ -1654,25 +1654,25 @@  discard block
 block discarded – undo
1654 1654
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1655 1655
  **/
1656 1656
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1657
-	$ratioWidth = $srcWidth / $maxWidth;
1658
-	$ratioHeight = $srcHeight / $maxHeight;
1659
-
1660
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1661
-		$destWidth = $srcWidth;
1662
-		$destHeight = $srcHeight;
1663
-	} elseif ($ratioWidth > $ratioHeight) {
1664
-		$destWidth = $srcWidth / $ratioHeight;
1665
-		$destHeight = $maxHeight;
1666
-	} else {
1667
-		$destWidth = $maxWidth;
1668
-		$destHeight = $srcHeight / $ratioWidth;
1669
-	}
1670
-
1671
-	return [
1672
-		intval(round($destWidth)),
1673
-		intval(round($destHeight)),
1674
-		min($ratioWidth, $ratioHeight)
1675
-	];
1657
+    $ratioWidth = $srcWidth / $maxWidth;
1658
+    $ratioHeight = $srcHeight / $maxHeight;
1659
+
1660
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1661
+        $destWidth = $srcWidth;
1662
+        $destHeight = $srcHeight;
1663
+    } elseif ($ratioWidth > $ratioHeight) {
1664
+        $destWidth = $srcWidth / $ratioHeight;
1665
+        $destHeight = $maxHeight;
1666
+    } else {
1667
+        $destWidth = $maxWidth;
1668
+        $destHeight = $srcHeight / $ratioWidth;
1669
+    }
1670
+
1671
+    return [
1672
+        intval(round($destWidth)),
1673
+        intval(round($destHeight)),
1674
+        min($ratioWidth, $ratioHeight)
1675
+    ];
1676 1676
 }
1677 1677
 
1678 1678
 
@@ -1685,12 +1685,12 @@  discard block
 block discarded – undo
1685 1685
  * @return string
1686 1686
  */
1687 1687
 function process_image_svg_identite($image) {
1688
-	if ($image['creer']) {
1689
-		$source = $image['fichier'];
1690
-		_image_gd_output($source, $image);
1691
-	}
1688
+    if ($image['creer']) {
1689
+        $source = $image['fichier'];
1690
+        _image_gd_output($source, $image);
1691
+    }
1692 1692
 
1693
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1693
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1694 1694
 }
1695 1695
 
1696 1696
 
@@ -1723,111 +1723,111 @@  discard block
 block discarded – undo
1723 1723
  *     Code HTML de la balise img produite
1724 1724
  **/
1725 1725
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1726
-	$image = false;
1727
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1728
-		$process = $GLOBALS['meta']['image_process'];
1729
-	}
1730
-	# determiner le format de sortie
1731
-	$format_sortie = false; // le choix par defaut sera bon
1732
-	if ($process == 'netpbm') {
1733
-		$format_sortie = 'jpg';
1734
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1735
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1736
-		// on verifie que l'extension choisie est bonne (en principe oui)
1737
-		$gd_formats = formats_image_acceptables(true);
1738
-		if (
1739
-			is_array($image)
1740
-			and (!in_array($image['format_dest'], $gd_formats)
1741
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1742
-			)
1743
-		) {
1744
-			if ($image['format_source'] == 'jpg') {
1745
-				$formats_sortie = ['jpg', 'png', 'gif'];
1746
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1747
-			{
1748
-				$formats_sortie = ['png', 'jpg', 'gif'];
1749
-			}
1750
-			// Choisir le format destination
1751
-			// - on sauve de preference en JPEG (meilleure compression)
1752
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1753
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1754
-			# pas *ecrire*
1755
-			$format_sortie = '';
1756
-			foreach ($formats_sortie as $fmt) {
1757
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1758
-					$format_sortie = $fmt;
1759
-					break;
1760
-				}
1761
-			}
1762
-			$image = false;
1763
-		}
1764
-	}
1765
-
1766
-	if (!is_array($image)) {
1767
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1768
-	}
1769
-
1770
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1771
-		spip_log("image_reduire_src:pas de version locale de $img");
1772
-		// on peut resizer en mode html si on dispose des elements
1773
-		if (
1774
-			$srcw = extraire_attribut($img, 'width')
1775
-			and $srch = extraire_attribut($img, 'height')
1776
-		) {
1777
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1778
-
1779
-			return _image_tag_changer_taille($img, $w, $h);
1780
-		}
1781
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1782
-		// sous la forme style='max-width: NNpx;'
1783
-		return inserer_attribut(
1784
-			$img,
1785
-			'style',
1786
-			"max-width: ${taille}px; max-height: ${taille_y}px"
1787
-		);
1788
-	}
1789
-
1790
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1791
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1792
-		if ($image['creer']) {
1793
-			@copy($image['fichier'], $image['fichier_dest']);
1794
-		}
1795
-
1796
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1797
-	}
1798
-
1799
-	if ($image['creer'] == false && !$force) {
1800
-		return _image_ecrire_tag(
1801
-			$image,
1802
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1803
-		);
1804
-	}
1805
-
1806
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1807
-		$destWidth = $image['largeur_dest'];
1808
-		$destHeight = $image['hauteur_dest'];
1809
-		$logo = $image['fichier'];
1810
-		$date = $image['date_src'];
1811
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1812
-
1813
-		if ($preview && $preview['fichier']) {
1814
-			$logo = $preview['fichier'];
1815
-			$destWidth = $preview['width'];
1816
-			$destHeight = $preview['height'];
1817
-			$date = $preview['date'];
1818
-		}
1819
-		// dans l'espace prive mettre un timestamp sur l'adresse
1820
-		// de l'image, de facon a tromper le cache du navigateur
1821
-		// quand on fait supprimer/reuploader un logo
1822
-		// (pas de filemtime si SAFE MODE)
1823
-		$date = test_espace_prive() ? ('?' . $date) : '';
1824
-
1825
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1826
-	}
1827
-	else {
1828
-		# BMP, tiff ... les redacteurs osent tout!
1829
-		return $img;
1830
-	}
1726
+    $image = false;
1727
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1728
+        $process = $GLOBALS['meta']['image_process'];
1729
+    }
1730
+    # determiner le format de sortie
1731
+    $format_sortie = false; // le choix par defaut sera bon
1732
+    if ($process == 'netpbm') {
1733
+        $format_sortie = 'jpg';
1734
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1735
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1736
+        // on verifie que l'extension choisie est bonne (en principe oui)
1737
+        $gd_formats = formats_image_acceptables(true);
1738
+        if (
1739
+            is_array($image)
1740
+            and (!in_array($image['format_dest'], $gd_formats)
1741
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1742
+            )
1743
+        ) {
1744
+            if ($image['format_source'] == 'jpg') {
1745
+                $formats_sortie = ['jpg', 'png', 'gif'];
1746
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1747
+            {
1748
+                $formats_sortie = ['png', 'jpg', 'gif'];
1749
+            }
1750
+            // Choisir le format destination
1751
+            // - on sauve de preference en JPEG (meilleure compression)
1752
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1753
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1754
+            # pas *ecrire*
1755
+            $format_sortie = '';
1756
+            foreach ($formats_sortie as $fmt) {
1757
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1758
+                    $format_sortie = $fmt;
1759
+                    break;
1760
+                }
1761
+            }
1762
+            $image = false;
1763
+        }
1764
+    }
1765
+
1766
+    if (!is_array($image)) {
1767
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1768
+    }
1769
+
1770
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1771
+        spip_log("image_reduire_src:pas de version locale de $img");
1772
+        // on peut resizer en mode html si on dispose des elements
1773
+        if (
1774
+            $srcw = extraire_attribut($img, 'width')
1775
+            and $srch = extraire_attribut($img, 'height')
1776
+        ) {
1777
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1778
+
1779
+            return _image_tag_changer_taille($img, $w, $h);
1780
+        }
1781
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1782
+        // sous la forme style='max-width: NNpx;'
1783
+        return inserer_attribut(
1784
+            $img,
1785
+            'style',
1786
+            "max-width: ${taille}px; max-height: ${taille_y}px"
1787
+        );
1788
+    }
1789
+
1790
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1791
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1792
+        if ($image['creer']) {
1793
+            @copy($image['fichier'], $image['fichier_dest']);
1794
+        }
1795
+
1796
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1797
+    }
1798
+
1799
+    if ($image['creer'] == false && !$force) {
1800
+        return _image_ecrire_tag(
1801
+            $image,
1802
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1803
+        );
1804
+    }
1805
+
1806
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1807
+        $destWidth = $image['largeur_dest'];
1808
+        $destHeight = $image['hauteur_dest'];
1809
+        $logo = $image['fichier'];
1810
+        $date = $image['date_src'];
1811
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1812
+
1813
+        if ($preview && $preview['fichier']) {
1814
+            $logo = $preview['fichier'];
1815
+            $destWidth = $preview['width'];
1816
+            $destHeight = $preview['height'];
1817
+            $date = $preview['date'];
1818
+        }
1819
+        // dans l'espace prive mettre un timestamp sur l'adresse
1820
+        // de l'image, de facon a tromper le cache du navigateur
1821
+        // quand on fait supprimer/reuploader un logo
1822
+        // (pas de filemtime si SAFE MODE)
1823
+        $date = test_espace_prive() ? ('?' . $date) : '';
1824
+
1825
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1826
+    }
1827
+    else {
1828
+        # BMP, tiff ... les redacteurs osent tout!
1829
+        return $img;
1830
+    }
1831 1831
 }
1832 1832
 
1833 1833
 /**
@@ -1841,145 +1841,145 @@  discard block
 block discarded – undo
1841 1841
  * Class phpthumb_functions
1842 1842
  */
1843 1843
 class phpthumb_functions {
1844
-	/**
1845
-	 * Retourne la couleur d'un pixel dans une image
1846
-	 *
1847
-	 * @param resource|GdImage $img
1848
-	 * @param int $x
1849
-	 * @param int $y
1850
-	 * @return array|bool
1851
-	 */
1852
-	public static function GetPixelColor(&$img, $x, $y) {
1853
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1854
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1855
-		}
1856
-		return false;
1857
-	}
1858
-
1859
-	/**
1860
-	 * Retourne un nombre dans une représentation en Little Endian
1861
-	 *
1862
-	 * @param int $number
1863
-	 * @param int $minbytes
1864
-	 * @return string
1865
-	 */
1866
-	public static function LittleEndian2String($number, $minbytes = 1) {
1867
-		$intstring = '';
1868
-		while ($number > 0) {
1869
-			$intstring = $intstring . chr($number & 255);
1870
-			$number >>= 8;
1871
-		}
1872
-
1873
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1874
-	}
1875
-
1876
-	/**
1877
-	 * Transforme une ressource GD en image au format ICO
1878
-	 *
1879
-	 * @param array $gd_image_array
1880
-	 *     Tableau de ressources d'images GD
1881
-	 * @return string
1882
-	 *     Image au format ICO
1883
-	 */
1884
-	public static function GD2ICOstring(&$gd_image_array) {
1885
-		foreach ($gd_image_array as $key => $gd_image) {
1886
-			$ImageWidths[$key] = ImageSX($gd_image);
1887
-			$ImageHeights[$key] = ImageSY($gd_image);
1888
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1889
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1890
-
1891
-			$icXOR[$key] = '';
1892
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1893
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1894
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1895
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1896
-					$r = $argb['red'];
1897
-					$g = $argb['green'];
1898
-					$b = $argb['blue'];
1899
-
1900
-					if ($bpp[$key] == 32) {
1901
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1902
-					} elseif ($bpp[$key] == 24) {
1903
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1904
-					}
1905
-
1906
-					if ($a < 128) {
1907
-						@$icANDmask[$key][$y] .= '1';
1908
-					} else {
1909
-						@$icANDmask[$key][$y] .= '0';
1910
-					}
1911
-				}
1912
-				// mask bits are 32-bit aligned per scanline
1913
-				while (strlen($icANDmask[$key][$y]) % 32) {
1914
-					$icANDmask[$key][$y] .= '0';
1915
-				}
1916
-			}
1917
-			$icAND[$key] = '';
1918
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1919
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1920
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1921
-				}
1922
-			}
1923
-		}
1924
-
1925
-		foreach ($gd_image_array as $key => $gd_image) {
1926
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1927
-
1928
-			// BITMAPINFOHEADER - 40 bytes
1929
-			$BitmapInfoHeader[$key] = '';
1930
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1931
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1932
-			// The biHeight member specifies the combined
1933
-			// height of the XOR and AND masks.
1934
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1935
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1936
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1937
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1938
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1939
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1940
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1941
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1942
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1943
-		}
1944
-
1945
-
1946
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1947
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1948
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1949
-
1950
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1951
-		foreach ($gd_image_array as $key => $gd_image) {
1952
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1953
-
1954
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1955
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1956
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1957
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1958
-
1959
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1960
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1961
-
1962
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1963
-			$icondata .= phpthumb_functions::LittleEndian2String(
1964
-				$dwBytesInRes,
1965
-				4
1966
-			);     // dwBytesInRes;	// How many bytes in this resource?
1967
-
1968
-			$icondata .= phpthumb_functions::LittleEndian2String(
1969
-				$dwImageOffset,
1970
-				4
1971
-			);    // dwImageOffset;   // Where in the file is this image?
1972
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1973
-			$dwImageOffset += strlen($icXOR[$key]);
1974
-			$dwImageOffset += strlen($icAND[$key]);
1975
-		}
1976
-
1977
-		foreach ($gd_image_array as $key => $gd_image) {
1978
-			$icondata .= $BitmapInfoHeader[$key];
1979
-			$icondata .= $icXOR[$key];
1980
-			$icondata .= $icAND[$key];
1981
-		}
1982
-
1983
-		return $icondata;
1984
-	}
1844
+    /**
1845
+     * Retourne la couleur d'un pixel dans une image
1846
+     *
1847
+     * @param resource|GdImage $img
1848
+     * @param int $x
1849
+     * @param int $y
1850
+     * @return array|bool
1851
+     */
1852
+    public static function GetPixelColor(&$img, $x, $y) {
1853
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1854
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1855
+        }
1856
+        return false;
1857
+    }
1858
+
1859
+    /**
1860
+     * Retourne un nombre dans une représentation en Little Endian
1861
+     *
1862
+     * @param int $number
1863
+     * @param int $minbytes
1864
+     * @return string
1865
+     */
1866
+    public static function LittleEndian2String($number, $minbytes = 1) {
1867
+        $intstring = '';
1868
+        while ($number > 0) {
1869
+            $intstring = $intstring . chr($number & 255);
1870
+            $number >>= 8;
1871
+        }
1872
+
1873
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1874
+    }
1875
+
1876
+    /**
1877
+     * Transforme une ressource GD en image au format ICO
1878
+     *
1879
+     * @param array $gd_image_array
1880
+     *     Tableau de ressources d'images GD
1881
+     * @return string
1882
+     *     Image au format ICO
1883
+     */
1884
+    public static function GD2ICOstring(&$gd_image_array) {
1885
+        foreach ($gd_image_array as $key => $gd_image) {
1886
+            $ImageWidths[$key] = ImageSX($gd_image);
1887
+            $ImageHeights[$key] = ImageSY($gd_image);
1888
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1889
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1890
+
1891
+            $icXOR[$key] = '';
1892
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1893
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1894
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1895
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1896
+                    $r = $argb['red'];
1897
+                    $g = $argb['green'];
1898
+                    $b = $argb['blue'];
1899
+
1900
+                    if ($bpp[$key] == 32) {
1901
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1902
+                    } elseif ($bpp[$key] == 24) {
1903
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1904
+                    }
1905
+
1906
+                    if ($a < 128) {
1907
+                        @$icANDmask[$key][$y] .= '1';
1908
+                    } else {
1909
+                        @$icANDmask[$key][$y] .= '0';
1910
+                    }
1911
+                }
1912
+                // mask bits are 32-bit aligned per scanline
1913
+                while (strlen($icANDmask[$key][$y]) % 32) {
1914
+                    $icANDmask[$key][$y] .= '0';
1915
+                }
1916
+            }
1917
+            $icAND[$key] = '';
1918
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1919
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1920
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1921
+                }
1922
+            }
1923
+        }
1924
+
1925
+        foreach ($gd_image_array as $key => $gd_image) {
1926
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1927
+
1928
+            // BITMAPINFOHEADER - 40 bytes
1929
+            $BitmapInfoHeader[$key] = '';
1930
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1931
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1932
+            // The biHeight member specifies the combined
1933
+            // height of the XOR and AND masks.
1934
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1935
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1936
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1937
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1938
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1939
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1940
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1941
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1942
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1943
+        }
1944
+
1945
+
1946
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1947
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1948
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1949
+
1950
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1951
+        foreach ($gd_image_array as $key => $gd_image) {
1952
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1953
+
1954
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1955
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1956
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1957
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1958
+
1959
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1960
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1961
+
1962
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1963
+            $icondata .= phpthumb_functions::LittleEndian2String(
1964
+                $dwBytesInRes,
1965
+                4
1966
+            );     // dwBytesInRes;	// How many bytes in this resource?
1967
+
1968
+            $icondata .= phpthumb_functions::LittleEndian2String(
1969
+                $dwImageOffset,
1970
+                4
1971
+            );    // dwImageOffset;   // Where in the file is this image?
1972
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1973
+            $dwImageOffset += strlen($icXOR[$key]);
1974
+            $dwImageOffset += strlen($icAND[$key]);
1975
+        }
1976
+
1977
+        foreach ($gd_image_array as $key => $gd_image) {
1978
+            $icondata .= $BitmapInfoHeader[$key];
1979
+            $icondata .= $icXOR[$key];
1980
+            $icondata .= $icAND[$key];
1981
+        }
1982
+
1983
+        return $icondata;
1984
+    }
1985 1985
 }
Please login to merge, or discard this patch.
Spacing   +66 added lines, -66 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,13 +1420,13 @@  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
 
1427 1427
 	// php5 imagemagick
1428 1428
 	elseif ($process == 'imagick') {
1429
-		$vignette = "$destination." . $format_sortie;
1429
+		$vignette = "$destination.".$format_sortie;
1430 1430
 
1431 1431
 		if (!class_exists(\Imagick::class)) {
1432 1432
 			spip_log('Classe Imagick absente !', _LOG_ERREUR);
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
 			$destHeight,
1441 1441
 			Imagick::FILTER_LANCZOS,
1442 1442
 			1
1443
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1443
+		); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1444 1444
 		$imagick->writeImage(realpath($vignette));
1445 1445
 
1446 1446
 		if (!@file_exists($vignette)) {
@@ -1458,11 +1458,11 @@  discard block
 block discarded – undo
1458 1458
 		if (_PNMSCALE_COMMAND == '') {
1459 1459
 			return;
1460 1460
 		}
1461
-		$vignette = $destination . '.' . $format_sortie;
1461
+		$vignette = $destination.'.'.$format_sortie;
1462 1462
 		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1463 1463
 		if ($format == 'jpg') {
1464 1464
 			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1465
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1465
+			exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1466 1466
 			if (!($s = @filesize($vignette))) {
1467 1467
 				spip_unlink($vignette);
1468 1468
 			}
@@ -1474,7 +1474,7 @@  discard block
 block discarded – undo
1474 1474
 		} else {
1475 1475
 			if ($format == 'gif') {
1476 1476
 				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1477
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
+				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1478 1478
 				if (!($s = @filesize($vignette))) {
1479 1479
 					spip_unlink($vignette);
1480 1480
 				}
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
 			} else {
1487 1487
 				if ($format == 'png') {
1488 1488
 					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1489
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
+					exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
1490 1490
 					if (!($s = @filesize($vignette))) {
1491 1491
 						spip_unlink($vignette);
1492 1492
 					}
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 			return;
1509 1509
 		}
1510 1510
 		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1511
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1511
+			spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels');
1512 1512
 
1513 1513
 			return;
1514 1514
 		}
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
 		// de l'image, de facon a tromper le cache du navigateur
1821 1821
 		// quand on fait supprimer/reuploader un logo
1822 1822
 		// (pas de filemtime si SAFE MODE)
1823
-		$date = test_espace_prive() ? ('?' . $date) : '';
1823
+		$date = test_espace_prive() ? ('?'.$date) : '';
1824 1824
 
1825 1825
 		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1826 1826
 	}
@@ -1866,7 +1866,7 @@  discard block
 block discarded – undo
1866 1866
 	public static function LittleEndian2String($number, $minbytes = 1) {
1867 1867
 		$intstring = '';
1868 1868
 		while ($number > 0) {
1869
-			$intstring = $intstring . chr($number & 255);
1869
+			$intstring = $intstring.chr($number & 255);
1870 1870
 			$number >>= 8;
1871 1871
 		}
1872 1872
 
@@ -1898,9 +1898,9 @@  discard block
 block discarded – undo
1898 1898
 					$b = $argb['blue'];
1899 1899
 
1900 1900
 					if ($bpp[$key] == 32) {
1901
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1901
+						$icXOR[$key] .= chr($b).chr($g).chr($r).chr($a);
1902 1902
 					} elseif ($bpp[$key] == 24) {
1903
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1903
+						$icXOR[$key] .= chr($b).chr($g).chr($r);
1904 1904
 					}
1905 1905
 
1906 1906
 					if ($a < 128) {
@@ -1927,48 +1927,48 @@  discard block
 block discarded – undo
1927 1927
 
1928 1928
 			// BITMAPINFOHEADER - 40 bytes
1929 1929
 			$BitmapInfoHeader[$key] = '';
1930
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1931
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1930
+			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD  biSize;
1931
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG   biWidth;
1932 1932
 			// The biHeight member specifies the combined
1933 1933
 			// height of the XOR and AND masks.
1934 1934
 			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1935
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1936
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1937
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1938
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1939
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1940
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1941
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1942
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1935
+			$BitmapInfoHeader[$key] .= "\x01\x00"; // WORD   biPlanes;
1936
+			$BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount;
1937
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biCompression;
1938
+			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD  biSizeImage;
1939
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biXPelsPerMeter;
1940
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG   biYPelsPerMeter;
1941
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrUsed;
1942
+			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD  biClrImportant;
1943 1943
 		}
1944 1944
 
1945 1945
 
1946
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1947
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1948
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1946
+		$icondata = "\x00\x00"; // idReserved;   // Reserved (must be 0)
1947
+		$icondata .= "\x01\x00"; // idType;	   // Resource Type (1 for icons)
1948
+		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount;	  // How many images?
1949 1949
 
1950 1950
 		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1951 1951
 		foreach ($gd_image_array as $key => $gd_image) {
1952 1952
 			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1953 1953
 
1954
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1955
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1956
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1957
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1954
+			$icondata .= chr($ImageWidths[$key]); // bWidth;		  // Width, in pixels, of the image
1955
+			$icondata .= chr($ImageHeights[$key]); // bHeight;		 // Height, in pixels, of the image
1956
+			$icondata .= chr($totalcolors[$key]); // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1957
+			$icondata .= "\x00"; // bReserved;	   // Reserved ( must be 0)
1958 1958
 
1959
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1960
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1959
+			$icondata .= "\x01\x00"; // wPlanes;		 // Color Planes
1960
+			$icondata .= chr($bpp[$key])."\x00"; // wBitCount;	   // Bits per pixel
1961 1961
 
1962 1962
 			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1963 1963
 			$icondata .= phpthumb_functions::LittleEndian2String(
1964 1964
 				$dwBytesInRes,
1965 1965
 				4
1966
-			);     // dwBytesInRes;	// How many bytes in this resource?
1966
+			); // dwBytesInRes;	// How many bytes in this resource?
1967 1967
 
1968 1968
 			$icondata .= phpthumb_functions::LittleEndian2String(
1969 1969
 				$dwImageOffset,
1970 1970
 				4
1971
-			);    // dwImageOffset;   // Where in the file is this image?
1971
+			); // dwImageOffset;   // Where in the file is this image?
1972 1972
 			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1973 1973
 			$dwImageOffset += strlen($icXOR[$key]);
1974 1974
 			$dwImageOffset += strlen($icAND[$key]);
Please login to merge, or discard this patch.