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