@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('inc/filtres'); // par precaution |
| 23 | 23 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -37,21 +37,21 @@ discard block |
||
| 37 | 37 | * Le code de la couleur en hexadécimal. |
| 38 | 38 | */ |
| 39 | 39 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 40 | - $red = dechex($red); |
|
| 41 | - $green = dechex($green); |
|
| 42 | - $blue = dechex($blue); |
|
| 43 | - |
|
| 44 | - if (strlen($red) == 1) { |
|
| 45 | - $red = '0' . $red; |
|
| 46 | - } |
|
| 47 | - if (strlen($green) == 1) { |
|
| 48 | - $green = '0' . $green; |
|
| 49 | - } |
|
| 50 | - if (strlen($blue) == 1) { |
|
| 51 | - $blue = '0' . $blue; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return "$red$green$blue"; |
|
| 40 | + $red = dechex($red); |
|
| 41 | + $green = dechex($green); |
|
| 42 | + $blue = dechex($blue); |
|
| 43 | + |
|
| 44 | + if (strlen($red) == 1) { |
|
| 45 | + $red = '0' . $red; |
|
| 46 | + } |
|
| 47 | + if (strlen($green) == 1) { |
|
| 48 | + $green = '0' . $green; |
|
| 49 | + } |
|
| 50 | + if (strlen($blue) == 1) { |
|
| 51 | + $blue = '0' . $blue; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return "$red$green$blue"; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -63,18 +63,18 @@ discard block |
||
| 63 | 63 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 64 | 64 | */ |
| 65 | 65 | function _couleur_hex_to_dec($couleur) { |
| 66 | - $couleur ??= ''; |
|
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 66 | + $couleur ??= ''; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,59 +120,59 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $H = null; |
|
| 124 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | - $var_G = ($G / 255); |
|
| 126 | - $var_B = ($B / 255); |
|
| 127 | - |
|
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | - |
|
| 132 | - $L = ($var_Max + $var_Min) / 2; |
|
| 133 | - |
|
| 134 | - if ($del_Max == 0) { |
|
| 135 | - //This is a gray, no chroma... |
|
| 136 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | - $S = 0; |
|
| 138 | - } else { |
|
| 139 | - // Chromatic data... |
|
| 140 | - if ($L < 0.5) { |
|
| 141 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | - } else { |
|
| 143 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - |
|
| 150 | - if ($var_R == $var_Max) { |
|
| 151 | - $H = $del_B - $del_G; |
|
| 152 | - } else { |
|
| 153 | - if ($var_G == $var_Max) { |
|
| 154 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | - } else { |
|
| 156 | - if ($var_B == $var_Max) { |
|
| 157 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if ($H < 0) { |
|
| 163 | - $H += 1; |
|
| 164 | - } |
|
| 165 | - if ($H > 1) { |
|
| 166 | - $H -= 1; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ret = []; |
|
| 171 | - $ret['h'] = $H; |
|
| 172 | - $ret['s'] = $S; |
|
| 173 | - $ret['l'] = $L; |
|
| 174 | - |
|
| 175 | - return $ret; |
|
| 123 | + $H = null; |
|
| 124 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | + $var_G = ($G / 255); |
|
| 126 | + $var_B = ($B / 255); |
|
| 127 | + |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | + |
|
| 132 | + $L = ($var_Max + $var_Min) / 2; |
|
| 133 | + |
|
| 134 | + if ($del_Max == 0) { |
|
| 135 | + //This is a gray, no chroma... |
|
| 136 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | + $S = 0; |
|
| 138 | + } else { |
|
| 139 | + // Chromatic data... |
|
| 140 | + if ($L < 0.5) { |
|
| 141 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | + } else { |
|
| 143 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + |
|
| 150 | + if ($var_R == $var_Max) { |
|
| 151 | + $H = $del_B - $del_G; |
|
| 152 | + } else { |
|
| 153 | + if ($var_G == $var_Max) { |
|
| 154 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | + } else { |
|
| 156 | + if ($var_B == $var_Max) { |
|
| 157 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if ($H < 0) { |
|
| 163 | + $H += 1; |
|
| 164 | + } |
|
| 165 | + if ($H > 1) { |
|
| 166 | + $H -= 1; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ret = []; |
|
| 171 | + $ret['h'] = $H; |
|
| 172 | + $ret['s'] = $S; |
|
| 173 | + $ret['l'] = $L; |
|
| 174 | + |
|
| 175 | + return $ret; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -188,52 +188,52 @@ discard block |
||
| 188 | 188 | * @return array |
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | - // helper |
|
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | - if ($vH < 0) { |
|
| 194 | - $vH += 1; |
|
| 195 | - } |
|
| 196 | - if ($vH > 1) { |
|
| 197 | - $vH -= 1; |
|
| 198 | - } |
|
| 199 | - if ((6 * $vH) < 1) { |
|
| 200 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | - } |
|
| 202 | - if ((2 * $vH) < 1) { |
|
| 203 | - return ($v2); |
|
| 204 | - } |
|
| 205 | - if ((3 * $vH) < 2) { |
|
| 206 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return ($v1); |
|
| 210 | - }; |
|
| 211 | - |
|
| 212 | - if ($S == 0) { |
|
| 213 | - // HSV values = 0 -> 1 |
|
| 214 | - $R = $L * 255; |
|
| 215 | - $G = $L * 255; |
|
| 216 | - $B = $L * 255; |
|
| 217 | - } else { |
|
| 218 | - if ($L < 0.5) { |
|
| 219 | - $var_2 = $L * (1 + $S); |
|
| 220 | - } else { |
|
| 221 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $var_1 = 2 * $L - $var_2; |
|
| 225 | - |
|
| 226 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $ret = []; |
|
| 232 | - $ret['r'] = floor($R); |
|
| 233 | - $ret['g'] = floor($G); |
|
| 234 | - $ret['b'] = floor($B); |
|
| 235 | - |
|
| 236 | - return $ret; |
|
| 191 | + // helper |
|
| 192 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | + if ($vH < 0) { |
|
| 194 | + $vH += 1; |
|
| 195 | + } |
|
| 196 | + if ($vH > 1) { |
|
| 197 | + $vH -= 1; |
|
| 198 | + } |
|
| 199 | + if ((6 * $vH) < 1) { |
|
| 200 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | + } |
|
| 202 | + if ((2 * $vH) < 1) { |
|
| 203 | + return ($v2); |
|
| 204 | + } |
|
| 205 | + if ((3 * $vH) < 2) { |
|
| 206 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return ($v1); |
|
| 210 | + }; |
|
| 211 | + |
|
| 212 | + if ($S == 0) { |
|
| 213 | + // HSV values = 0 -> 1 |
|
| 214 | + $R = $L * 255; |
|
| 215 | + $G = $L * 255; |
|
| 216 | + $B = $L * 255; |
|
| 217 | + } else { |
|
| 218 | + if ($L < 0.5) { |
|
| 219 | + $var_2 = $L * (1 + $S); |
|
| 220 | + } else { |
|
| 221 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $var_1 = 2 * $L - $var_2; |
|
| 225 | + |
|
| 226 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $ret = []; |
|
| 232 | + $ret['r'] = floor($R); |
|
| 233 | + $ret['g'] = floor($G); |
|
| 234 | + $ret['b'] = floor($B); |
|
| 235 | + |
|
| 236 | + return $ret; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 252 | 252 | */ |
| 253 | 253 | function statut_effacer_images_temporaires($stat) { |
| 254 | - static $statut = false; // par defaut on grave toute les images |
|
| 255 | - if ($stat === 'get') { |
|
| 256 | - return $statut; |
|
| 257 | - } |
|
| 258 | - $statut = $stat ? true : false; |
|
| 254 | + static $statut = false; // par defaut on grave toute les images |
|
| 255 | + if ($stat === 'get') { |
|
| 256 | + return $statut; |
|
| 257 | + } |
|
| 258 | + $statut = $stat ? true : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -308,247 +308,247 @@ discard block |
||
| 308 | 308 | * - array : tableau décrivant de l'image |
| 309 | 309 | */ |
| 310 | 310 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 311 | - $ret = []; |
|
| 312 | - $f = null; |
|
| 313 | - static $images_recalcul = []; |
|
| 314 | - if (strlen($img) == 0) { |
|
| 315 | - return false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | - if (strlen($source) < 1) { |
|
| 320 | - $source = $img; |
|
| 321 | - $img = "<img src='$source' />"; |
|
| 322 | - } elseif ( |
|
| 323 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | - ) { |
|
| 327 | - # gerer img src="data:....base64" |
|
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | - if (!file_exists($local)) { |
|
| 330 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | - } |
|
| 332 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | - $sanitizer($local); |
|
| 334 | - } |
|
| 335 | - $source = $local; |
|
| 336 | - $img = inserer_attribut($img, 'src', $source); |
|
| 337 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | - $img = inserer_attribut($img, 'width', ''); |
|
| 339 | - $img = inserer_attribut($img, 'height', ''); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // les protocoles web prennent au moins 3 lettres |
|
| 343 | - if (tester_url_absolue($source)) { |
|
| 344 | - include_spip('inc/distant'); |
|
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | - if (!$fichier) { |
|
| 347 | - return ''; |
|
| 348 | - } |
|
| 349 | - if ( |
|
| 350 | - $extension = _image_trouver_extension($fichier) |
|
| 351 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | - ) { |
|
| 353 | - $sanitizer($fichier); |
|
| 354 | - } |
|
| 355 | - } else { |
|
| 356 | - // enlever le timestamp eventuel |
|
| 357 | - if (strpos($source, '?') !== false) { |
|
| 358 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | - } |
|
| 360 | - if ( |
|
| 361 | - strpos($source, '?') !== false |
|
| 362 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | - ) { |
|
| 365 | - $source = $f; |
|
| 366 | - } |
|
| 367 | - $fichier = $source; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $terminaison_dest = ''; |
|
| 371 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ( |
|
| 376 | - $forcer_format !== false |
|
| 377 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | - ) { |
|
| 380 | - $terminaison_dest = $forcer_format; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - if (!$terminaison_dest) { |
|
| 384 | - return false; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | - $fichier_dest = $nom_fichier; |
|
| 389 | - if ( |
|
| 390 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | - or @file_exists($f = $fichier) |
|
| 392 | - ) { |
|
| 393 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | - // au lieu de faire un acces disque sur le fichier |
|
| 395 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | - $date_src = @filemtime($f); |
|
| 397 | - } elseif ( |
|
| 398 | - @file_exists($f = "$fichier.src") |
|
| 399 | - and lire_fichier($f, $valeurs) |
|
| 400 | - and $valeurs = unserialize($valeurs) |
|
| 401 | - and isset($valeurs['hauteur_dest']) |
|
| 402 | - and isset($valeurs['largeur_dest']) |
|
| 403 | - ) { |
|
| 404 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | - $date_src = $valeurs['date']; |
|
| 407 | - } // pas de fichier source par la |
|
| 408 | - else { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - // pas de taille mesurable ? |
|
| 413 | - if (!$ret['hauteur'] |
|
| 414 | - or !($ret['hauteur'] = intval(round($ret['hauteur']))) |
|
| 415 | - or !$ret['largeur'] |
|
| 416 | - or !($ret['largeur'] = intval(round($ret['largeur']))) |
|
| 417 | - ) { |
|
| 418 | - return false; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - // les images calculees dependent du chemin du fichier source |
|
| 422 | - // 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 |
|
| 423 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 424 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 425 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 426 | - // alors que ca concerne peu de site au final |
|
| 427 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 428 | - $identifiant = $fichier; |
|
| 429 | - |
|
| 430 | - // cas general : |
|
| 431 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 432 | - // cas particulier de reduire : |
|
| 433 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 434 | - $cache = 'cache-gd2'; |
|
| 435 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 436 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 437 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 438 | - $ret['largeur_dest'] = $destWidth; |
|
| 439 | - $ret['hauteur_dest'] = $destHeight; |
|
| 440 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 441 | - $cache = 'cache-vignettes'; |
|
| 442 | - $fichier_dest = basename($fichier_dest); |
|
| 443 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 444 | - // on garde la terminaison initiale car image simplement copiee |
|
| 445 | - // et on postfixe son nom avec un md5 du path |
|
| 446 | - $terminaison_dest = $terminaison; |
|
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 448 | - } else { |
|
| 449 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 450 | - } |
|
| 451 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | - $cache = sous_repertoire($cache, $effet); |
|
| 453 | - } else { |
|
| 454 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 455 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 456 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 457 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 461 | - |
|
| 462 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 463 | - |
|
| 464 | - $creer = true; |
|
| 465 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 466 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 467 | - $images_recalcul[$fichier_dest] = true; |
|
| 468 | - } else { |
|
| 469 | - if (@file_exists($f = $fichier_dest)) { |
|
| 470 | - if (filemtime($f) >= $date_src) { |
|
| 471 | - $creer = false; |
|
| 472 | - } |
|
| 473 | - } else { |
|
| 474 | - if ( |
|
| 475 | - @file_exists($f = "$fichier_dest.src") |
|
| 476 | - and lire_fichier($f, $valeurs) |
|
| 477 | - and $valeurs = unserialize($valeurs) |
|
| 478 | - and $valeurs['date'] >= $date_src |
|
| 479 | - ) { |
|
| 480 | - $creer = false; |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - if ($creer) { |
|
| 485 | - if (!@file_exists($fichier)) { |
|
| 486 | - if (!@file_exists("$fichier.src")) { |
|
| 487 | - spip_log("Image absente : $fichier"); |
|
| 488 | - |
|
| 489 | - return false; |
|
| 490 | - } |
|
| 491 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 492 | - reconstruire_image_intermediaire($fichier); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if ($creer) { |
|
| 497 | - spip_log( |
|
| 498 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 499 | - 'images' . _LOG_DEBUG |
|
| 500 | - ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 504 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 505 | - $ret['fichier'] = $fichier; |
|
| 506 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 507 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 508 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 509 | - $ret['format_dest'] = $terminaison_dest; |
|
| 510 | - $ret['date_src'] = $date_src; |
|
| 511 | - $ret['creer'] = $creer; |
|
| 512 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 513 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 514 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 515 | - $ret['tag'] = $img; |
|
| 516 | - if ($fonction_creation) { |
|
| 517 | - $ret['reconstruction'] = $fonction_creation; |
|
| 518 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 519 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 520 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 521 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 525 | - 'args' => [ |
|
| 526 | - 'img' => $img, |
|
| 527 | - 'effet' => $effet, |
|
| 528 | - 'forcer_format' => $forcer_format, |
|
| 529 | - 'fonction_creation' => $fonction_creation, |
|
| 530 | - 'find_in_path' => $find_in_path, |
|
| 531 | - ], |
|
| 532 | - 'data' => $ret |
|
| 533 | - ]); |
|
| 534 | - |
|
| 535 | - // une globale pour le debug en cas de crash memoire |
|
| 536 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 537 | - |
|
| 538 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 539 | - if ($term_fonction === 'svg') { |
|
| 540 | - if ($creer and !$support_svg) { |
|
| 541 | - process_image_svg_identite($ret); |
|
| 542 | - $ret['creer'] = false; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - else { |
|
| 546 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - return $ret; |
|
| 311 | + $ret = []; |
|
| 312 | + $f = null; |
|
| 313 | + static $images_recalcul = []; |
|
| 314 | + if (strlen($img) == 0) { |
|
| 315 | + return false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | + if (strlen($source) < 1) { |
|
| 320 | + $source = $img; |
|
| 321 | + $img = "<img src='$source' />"; |
|
| 322 | + } elseif ( |
|
| 323 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | + ) { |
|
| 327 | + # gerer img src="data:....base64" |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | + if (!file_exists($local)) { |
|
| 330 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | + } |
|
| 332 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | + $sanitizer($local); |
|
| 334 | + } |
|
| 335 | + $source = $local; |
|
| 336 | + $img = inserer_attribut($img, 'src', $source); |
|
| 337 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | + $img = inserer_attribut($img, 'width', ''); |
|
| 339 | + $img = inserer_attribut($img, 'height', ''); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // les protocoles web prennent au moins 3 lettres |
|
| 343 | + if (tester_url_absolue($source)) { |
|
| 344 | + include_spip('inc/distant'); |
|
| 345 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | + if (!$fichier) { |
|
| 347 | + return ''; |
|
| 348 | + } |
|
| 349 | + if ( |
|
| 350 | + $extension = _image_trouver_extension($fichier) |
|
| 351 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | + ) { |
|
| 353 | + $sanitizer($fichier); |
|
| 354 | + } |
|
| 355 | + } else { |
|
| 356 | + // enlever le timestamp eventuel |
|
| 357 | + if (strpos($source, '?') !== false) { |
|
| 358 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | + } |
|
| 360 | + if ( |
|
| 361 | + strpos($source, '?') !== false |
|
| 362 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | + ) { |
|
| 365 | + $source = $f; |
|
| 366 | + } |
|
| 367 | + $fichier = $source; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $terminaison_dest = ''; |
|
| 371 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ( |
|
| 376 | + $forcer_format !== false |
|
| 377 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | + ) { |
|
| 380 | + $terminaison_dest = $forcer_format; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + if (!$terminaison_dest) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | + $fichier_dest = $nom_fichier; |
|
| 389 | + if ( |
|
| 390 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | + or @file_exists($f = $fichier) |
|
| 392 | + ) { |
|
| 393 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | + // au lieu de faire un acces disque sur le fichier |
|
| 395 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | + $date_src = @filemtime($f); |
|
| 397 | + } elseif ( |
|
| 398 | + @file_exists($f = "$fichier.src") |
|
| 399 | + and lire_fichier($f, $valeurs) |
|
| 400 | + and $valeurs = unserialize($valeurs) |
|
| 401 | + and isset($valeurs['hauteur_dest']) |
|
| 402 | + and isset($valeurs['largeur_dest']) |
|
| 403 | + ) { |
|
| 404 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | + $date_src = $valeurs['date']; |
|
| 407 | + } // pas de fichier source par la |
|
| 408 | + else { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + // pas de taille mesurable ? |
|
| 413 | + if (!$ret['hauteur'] |
|
| 414 | + or !($ret['hauteur'] = intval(round($ret['hauteur']))) |
|
| 415 | + or !$ret['largeur'] |
|
| 416 | + or !($ret['largeur'] = intval(round($ret['largeur']))) |
|
| 417 | + ) { |
|
| 418 | + return false; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + // les images calculees dependent du chemin du fichier source |
|
| 422 | + // 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 |
|
| 423 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 424 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 425 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 426 | + // alors que ca concerne peu de site au final |
|
| 427 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 428 | + $identifiant = $fichier; |
|
| 429 | + |
|
| 430 | + // cas general : |
|
| 431 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 432 | + // cas particulier de reduire : |
|
| 433 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 434 | + $cache = 'cache-gd2'; |
|
| 435 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 436 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 437 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 438 | + $ret['largeur_dest'] = $destWidth; |
|
| 439 | + $ret['hauteur_dest'] = $destHeight; |
|
| 440 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 441 | + $cache = 'cache-vignettes'; |
|
| 442 | + $fichier_dest = basename($fichier_dest); |
|
| 443 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 444 | + // on garde la terminaison initiale car image simplement copiee |
|
| 445 | + // et on postfixe son nom avec un md5 du path |
|
| 446 | + $terminaison_dest = $terminaison; |
|
| 447 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 448 | + } else { |
|
| 449 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 450 | + } |
|
| 451 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | + $cache = sous_repertoire($cache, $effet); |
|
| 453 | + } else { |
|
| 454 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 455 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 456 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 457 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 461 | + |
|
| 462 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 463 | + |
|
| 464 | + $creer = true; |
|
| 465 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 466 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 467 | + $images_recalcul[$fichier_dest] = true; |
|
| 468 | + } else { |
|
| 469 | + if (@file_exists($f = $fichier_dest)) { |
|
| 470 | + if (filemtime($f) >= $date_src) { |
|
| 471 | + $creer = false; |
|
| 472 | + } |
|
| 473 | + } else { |
|
| 474 | + if ( |
|
| 475 | + @file_exists($f = "$fichier_dest.src") |
|
| 476 | + and lire_fichier($f, $valeurs) |
|
| 477 | + and $valeurs = unserialize($valeurs) |
|
| 478 | + and $valeurs['date'] >= $date_src |
|
| 479 | + ) { |
|
| 480 | + $creer = false; |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + if ($creer) { |
|
| 485 | + if (!@file_exists($fichier)) { |
|
| 486 | + if (!@file_exists("$fichier.src")) { |
|
| 487 | + spip_log("Image absente : $fichier"); |
|
| 488 | + |
|
| 489 | + return false; |
|
| 490 | + } |
|
| 491 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 492 | + reconstruire_image_intermediaire($fichier); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if ($creer) { |
|
| 497 | + spip_log( |
|
| 498 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 499 | + 'images' . _LOG_DEBUG |
|
| 500 | + ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 504 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 505 | + $ret['fichier'] = $fichier; |
|
| 506 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 507 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 508 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 509 | + $ret['format_dest'] = $terminaison_dest; |
|
| 510 | + $ret['date_src'] = $date_src; |
|
| 511 | + $ret['creer'] = $creer; |
|
| 512 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 513 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 514 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 515 | + $ret['tag'] = $img; |
|
| 516 | + if ($fonction_creation) { |
|
| 517 | + $ret['reconstruction'] = $fonction_creation; |
|
| 518 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 519 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 520 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 521 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 525 | + 'args' => [ |
|
| 526 | + 'img' => $img, |
|
| 527 | + 'effet' => $effet, |
|
| 528 | + 'forcer_format' => $forcer_format, |
|
| 529 | + 'fonction_creation' => $fonction_creation, |
|
| 530 | + 'find_in_path' => $find_in_path, |
|
| 531 | + ], |
|
| 532 | + 'data' => $ret |
|
| 533 | + ]); |
|
| 534 | + |
|
| 535 | + // une globale pour le debug en cas de crash memoire |
|
| 536 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 537 | + |
|
| 538 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 539 | + if ($term_fonction === 'svg') { |
|
| 540 | + if ($creer and !$support_svg) { |
|
| 541 | + process_image_svg_identite($ret); |
|
| 542 | + $ret['creer'] = false; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + else { |
|
| 546 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + return $ret; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -557,54 +557,54 @@ discard block |
||
| 557 | 557 | * @return array |
| 558 | 558 | */ |
| 559 | 559 | function _image_extensions_acceptees_en_entree() { |
| 560 | - static $extensions = null; |
|
| 561 | - if (empty($extensions)) { |
|
| 562 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 563 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 564 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 565 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 566 | - $extensions = array_map('trim', $extensions); |
|
| 567 | - $extensions = array_filter($extensions); |
|
| 568 | - if (in_array('jpg', $extensions)) { |
|
| 569 | - $extensions[] = 'jpeg'; |
|
| 570 | - } |
|
| 571 | - $extensions = array_unique($extensions); |
|
| 572 | - } |
|
| 573 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - return $extensions; |
|
| 560 | + static $extensions = null; |
|
| 561 | + if (empty($extensions)) { |
|
| 562 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 563 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 564 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 565 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 566 | + $extensions = array_map('trim', $extensions); |
|
| 567 | + $extensions = array_filter($extensions); |
|
| 568 | + if (in_array('jpg', $extensions)) { |
|
| 569 | + $extensions[] = 'jpeg'; |
|
| 570 | + } |
|
| 571 | + $extensions = array_unique($extensions); |
|
| 572 | + } |
|
| 573 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + return $extensions; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
| 580 | 580 | * @return array|string[]|null |
| 581 | 581 | */ |
| 582 | 582 | function _image_extensions_acceptees_en_sortie() { |
| 583 | - static $extensions = null; |
|
| 584 | - if (empty($extensions)) { |
|
| 585 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 586 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 587 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 588 | - $extensions = array_diff($extensions, ['gif']); |
|
| 589 | - } |
|
| 590 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 591 | - $extensions = array_diff($extensions, ['webp']); |
|
| 592 | - } |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - return $extensions; |
|
| 583 | + static $extensions = null; |
|
| 584 | + if (empty($extensions)) { |
|
| 585 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 586 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 587 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 588 | + $extensions = array_diff($extensions, ['gif']); |
|
| 589 | + } |
|
| 590 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 591 | + $extensions = array_diff($extensions, ['webp']); |
|
| 592 | + } |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + return $extensions; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | function _image_extension_normalisee($extension) { |
| 599 | - $extension = strtolower($extension); |
|
| 600 | - if ($extension === 'jpeg') { |
|
| 601 | - $extension = 'jpg'; |
|
| 602 | - } |
|
| 603 | - return $extension; |
|
| 599 | + $extension = strtolower($extension); |
|
| 600 | + if ($extension === 'jpeg') { |
|
| 601 | + $extension = 'jpg'; |
|
| 602 | + } |
|
| 603 | + return $extension; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | function _image_extensions_conservent_transparence() { |
| 607 | - return ['png', 'webp']; |
|
| 607 | + return ['png', 'webp']; |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | |
@@ -614,12 +614,12 @@ discard block |
||
| 614 | 614 | * @return string |
| 615 | 615 | */ |
| 616 | 616 | function _image_trouver_extension($path) { |
| 617 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 618 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 619 | - $terminaison = strtolower($regs[1]); |
|
| 620 | - return $terminaison; |
|
| 621 | - } |
|
| 622 | - return ''; |
|
| 617 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 618 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 619 | + $terminaison = strtolower($regs[1]); |
|
| 620 | + return $terminaison; |
|
| 621 | + } |
|
| 622 | + return ''; |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
@@ -630,33 +630,33 @@ discard block |
||
| 630 | 630 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 631 | 631 | */ |
| 632 | 632 | function _image_trouver_extension_pertinente($path) { |
| 633 | - $path = supprimer_timestamp($path); |
|
| 634 | - $terminaison = _image_trouver_extension($path); |
|
| 635 | - if ($terminaison == 'jpg') { |
|
| 636 | - $terminaison = 'jpeg'; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - if (!file_exists($path)) { |
|
| 640 | - return $terminaison; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if (!$info = @spip_getimagesize($path)) { |
|
| 644 | - return $terminaison; |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - if (isset($info['mime'])) { |
|
| 648 | - $mime = $info['mime']; |
|
| 649 | - } |
|
| 650 | - else { |
|
| 651 | - $mime = image_type_to_mime_type($info[2]); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 655 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 656 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 657 | - $terminaison = $_terminaison; |
|
| 658 | - } |
|
| 659 | - return $terminaison; |
|
| 633 | + $path = supprimer_timestamp($path); |
|
| 634 | + $terminaison = _image_trouver_extension($path); |
|
| 635 | + if ($terminaison == 'jpg') { |
|
| 636 | + $terminaison = 'jpeg'; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + if (!file_exists($path)) { |
|
| 640 | + return $terminaison; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if (!$info = @spip_getimagesize($path)) { |
|
| 644 | + return $terminaison; |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + if (isset($info['mime'])) { |
|
| 648 | + $mime = $info['mime']; |
|
| 649 | + } |
|
| 650 | + else { |
|
| 651 | + $mime = image_type_to_mime_type($info[2]); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 655 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 656 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 657 | + $terminaison = $_terminaison; |
|
| 658 | + } |
|
| 659 | + return $terminaison; |
|
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | /** |
@@ -664,36 +664,36 @@ discard block |
||
| 664 | 664 | * @return string |
| 665 | 665 | */ |
| 666 | 666 | function _image_trouver_extension_depuis_mime($mime) { |
| 667 | - switch (strtolower($mime)) { |
|
| 668 | - case 'image/png': |
|
| 669 | - case 'image/x-png': |
|
| 670 | - $terminaison = 'png'; |
|
| 671 | - break; |
|
| 672 | - |
|
| 673 | - case 'image/jpg': |
|
| 674 | - case 'image/jpeg': |
|
| 675 | - case 'image/pjpeg': |
|
| 676 | - $terminaison = 'jpeg'; |
|
| 677 | - break; |
|
| 678 | - |
|
| 679 | - case 'image/gif': |
|
| 680 | - $terminaison = 'gif'; |
|
| 681 | - break; |
|
| 682 | - |
|
| 683 | - case 'image/webp': |
|
| 684 | - case 'image/x-webp': |
|
| 685 | - $terminaison = 'webp'; |
|
| 686 | - break; |
|
| 687 | - |
|
| 688 | - case 'image/svg+xml': |
|
| 689 | - $terminaison = 'svg'; |
|
| 690 | - break; |
|
| 691 | - |
|
| 692 | - default: |
|
| 693 | - $terminaison = ''; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $terminaison; |
|
| 667 | + switch (strtolower($mime)) { |
|
| 668 | + case 'image/png': |
|
| 669 | + case 'image/x-png': |
|
| 670 | + $terminaison = 'png'; |
|
| 671 | + break; |
|
| 672 | + |
|
| 673 | + case 'image/jpg': |
|
| 674 | + case 'image/jpeg': |
|
| 675 | + case 'image/pjpeg': |
|
| 676 | + $terminaison = 'jpeg'; |
|
| 677 | + break; |
|
| 678 | + |
|
| 679 | + case 'image/gif': |
|
| 680 | + $terminaison = 'gif'; |
|
| 681 | + break; |
|
| 682 | + |
|
| 683 | + case 'image/webp': |
|
| 684 | + case 'image/x-webp': |
|
| 685 | + $terminaison = 'webp'; |
|
| 686 | + break; |
|
| 687 | + |
|
| 688 | + case 'image/svg+xml': |
|
| 689 | + $terminaison = 'svg'; |
|
| 690 | + break; |
|
| 691 | + |
|
| 692 | + default: |
|
| 693 | + $terminaison = ''; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $terminaison; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -713,18 +713,18 @@ discard block |
||
| 713 | 713 | * Une ressource de type Image GD. |
| 714 | 714 | */ |
| 715 | 715 | function _imagecreatefrom_func(string $func, string $filename) { |
| 716 | - if (!function_exists($func)) { |
|
| 717 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 718 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 719 | - return null; |
|
| 720 | - } |
|
| 721 | - $img = @$func($filename); |
|
| 722 | - if (!$img) { |
|
| 723 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 724 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 725 | - $img = imagecreate(10, 10); |
|
| 726 | - } |
|
| 727 | - return $img; |
|
| 716 | + if (!function_exists($func)) { |
|
| 717 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 718 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 719 | + return null; |
|
| 720 | + } |
|
| 721 | + $img = @$func($filename); |
|
| 722 | + if (!$img) { |
|
| 723 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 724 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 725 | + $img = imagecreate(10, 10); |
|
| 726 | + } |
|
| 727 | + return $img; |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | * Une ressource de type Image GD. |
| 741 | 741 | */ |
| 742 | 742 | function _imagecreatefromjpeg($filename) { |
| 743 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 743 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | * Une ressource de type Image GD. |
| 757 | 757 | */ |
| 758 | 758 | function _imagecreatefrompng($filename) { |
| 759 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 759 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | /** |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | * Une ressource de type Image GD. |
| 773 | 773 | */ |
| 774 | 774 | function _imagecreatefromgif($filename) { |
| 775 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 775 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | * Une ressource de type Image GD. |
| 790 | 790 | */ |
| 791 | 791 | function _imagecreatefromwebp($filename) { |
| 792 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 792 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | 795 | /** |
@@ -807,24 +807,24 @@ discard block |
||
| 807 | 807 | * - true si une image est bien retournée. |
| 808 | 808 | */ |
| 809 | 809 | function _image_imagepng($img, $fichier) { |
| 810 | - if (!function_exists('imagepng')) { |
|
| 811 | - return false; |
|
| 812 | - } |
|
| 813 | - $tmp = $fichier . '.tmp'; |
|
| 814 | - $ret = imagepng($img, $tmp); |
|
| 815 | - if (file_exists($tmp)) { |
|
| 816 | - $taille_test = @getimagesize($tmp); |
|
| 817 | - if (empty($taille_test[0])) { |
|
| 818 | - return false; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 822 | - @rename($tmp, $fichier); |
|
| 823 | - |
|
| 824 | - return $ret; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - return false; |
|
| 810 | + if (!function_exists('imagepng')) { |
|
| 811 | + return false; |
|
| 812 | + } |
|
| 813 | + $tmp = $fichier . '.tmp'; |
|
| 814 | + $ret = imagepng($img, $tmp); |
|
| 815 | + if (file_exists($tmp)) { |
|
| 816 | + $taille_test = @getimagesize($tmp); |
|
| 817 | + if (empty($taille_test[0])) { |
|
| 818 | + return false; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 822 | + @rename($tmp, $fichier); |
|
| 823 | + |
|
| 824 | + return $ret; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + return false; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | /** |
@@ -842,24 +842,24 @@ discard block |
||
| 842 | 842 | * - true si une image est bien retournée. |
| 843 | 843 | */ |
| 844 | 844 | function _image_imagegif($img, $fichier) { |
| 845 | - if (!function_exists('imagegif')) { |
|
| 846 | - return false; |
|
| 847 | - } |
|
| 848 | - $tmp = $fichier . '.tmp'; |
|
| 849 | - $ret = imagegif($img, $tmp); |
|
| 850 | - if (file_exists($tmp)) { |
|
| 851 | - $taille_test = @getimagesize($tmp); |
|
| 852 | - if (empty($taille_test[0])) { |
|
| 853 | - return false; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 857 | - @rename($tmp, $fichier); |
|
| 858 | - |
|
| 859 | - return $ret; |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - return false; |
|
| 845 | + if (!function_exists('imagegif')) { |
|
| 846 | + return false; |
|
| 847 | + } |
|
| 848 | + $tmp = $fichier . '.tmp'; |
|
| 849 | + $ret = imagegif($img, $tmp); |
|
| 850 | + if (file_exists($tmp)) { |
|
| 851 | + $taille_test = @getimagesize($tmp); |
|
| 852 | + if (empty($taille_test[0])) { |
|
| 853 | + return false; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 857 | + @rename($tmp, $fichier); |
|
| 858 | + |
|
| 859 | + return $ret; |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + return false; |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | /** |
@@ -882,29 +882,29 @@ discard block |
||
| 882 | 882 | * - true si une image est bien retournée. |
| 883 | 883 | */ |
| 884 | 884 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 885 | - if (!function_exists('imagejpeg')) { |
|
| 886 | - return false; |
|
| 887 | - } |
|
| 888 | - $tmp = $fichier . '.tmp'; |
|
| 885 | + if (!function_exists('imagejpeg')) { |
|
| 886 | + return false; |
|
| 887 | + } |
|
| 888 | + $tmp = $fichier . '.tmp'; |
|
| 889 | 889 | |
| 890 | - // Enable interlancing |
|
| 891 | - imageinterlace($img, true); |
|
| 890 | + // Enable interlancing |
|
| 891 | + imageinterlace($img, true); |
|
| 892 | 892 | |
| 893 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 893 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 894 | 894 | |
| 895 | - if (file_exists($tmp)) { |
|
| 896 | - $taille_test = @getimagesize($tmp); |
|
| 897 | - if (empty($taille_test[0])) { |
|
| 898 | - return false; |
|
| 899 | - } |
|
| 895 | + if (file_exists($tmp)) { |
|
| 896 | + $taille_test = @getimagesize($tmp); |
|
| 897 | + if (empty($taille_test[0])) { |
|
| 898 | + return false; |
|
| 899 | + } |
|
| 900 | 900 | |
| 901 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 902 | - @rename($tmp, $fichier); |
|
| 901 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 902 | + @rename($tmp, $fichier); |
|
| 903 | 903 | |
| 904 | - return $ret; |
|
| 905 | - } |
|
| 904 | + return $ret; |
|
| 905 | + } |
|
| 906 | 906 | |
| 907 | - return false; |
|
| 907 | + return false; |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -922,9 +922,9 @@ discard block |
||
| 922 | 922 | * true si le fichier a bien été créé ; false sinon. |
| 923 | 923 | */ |
| 924 | 924 | function _image_imageico($img, $fichier) { |
| 925 | - $gd_image_array = [$img]; |
|
| 925 | + $gd_image_array = [$img]; |
|
| 926 | 926 | |
| 927 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 927 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 928 | 928 | } |
| 929 | 929 | |
| 930 | 930 | |
@@ -943,24 +943,24 @@ discard block |
||
| 943 | 943 | * - true si une image est bien retournée. |
| 944 | 944 | */ |
| 945 | 945 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 946 | - if (!function_exists('imagewebp')) { |
|
| 947 | - return false; |
|
| 948 | - } |
|
| 949 | - $tmp = $fichier . '.tmp'; |
|
| 950 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 951 | - if (file_exists($tmp)) { |
|
| 952 | - $taille_test = @getimagesize($tmp); |
|
| 953 | - if (empty($taille_test[0])) { |
|
| 954 | - return false; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 958 | - @rename($tmp, $fichier); |
|
| 959 | - |
|
| 960 | - return $ret; |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - return false; |
|
| 946 | + if (!function_exists('imagewebp')) { |
|
| 947 | + return false; |
|
| 948 | + } |
|
| 949 | + $tmp = $fichier . '.tmp'; |
|
| 950 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 951 | + if (file_exists($tmp)) { |
|
| 952 | + $taille_test = @getimagesize($tmp); |
|
| 953 | + if (empty($taille_test[0])) { |
|
| 954 | + return false; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 958 | + @rename($tmp, $fichier); |
|
| 959 | + |
|
| 960 | + return $ret; |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + return false; |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | 966 | /** |
@@ -980,35 +980,35 @@ discard block |
||
| 980 | 980 | */ |
| 981 | 981 | function _image_imagesvg($img, $fichier) { |
| 982 | 982 | |
| 983 | - $tmp = $fichier . '.tmp'; |
|
| 984 | - if (strpos($img, '<') === false) { |
|
| 985 | - $img = supprimer_timestamp($img); |
|
| 986 | - if (!file_exists($img)) { |
|
| 987 | - return false; |
|
| 988 | - } |
|
| 989 | - @copy($img, $tmp); |
|
| 990 | - if (filesize($tmp) == filesize($img)) { |
|
| 991 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 992 | - @rename($tmp, $fichier); |
|
| 993 | - return true; |
|
| 994 | - } |
|
| 995 | - return false; |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - file_put_contents($tmp, $img); |
|
| 999 | - if (file_exists($tmp)) { |
|
| 1000 | - $taille_test = spip_getimagesize($tmp); |
|
| 1001 | - if (empty($taille_test[0])) { |
|
| 1002 | - return false; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1006 | - @rename($tmp, $fichier); |
|
| 1007 | - |
|
| 1008 | - return true; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - return false; |
|
| 983 | + $tmp = $fichier . '.tmp'; |
|
| 984 | + if (strpos($img, '<') === false) { |
|
| 985 | + $img = supprimer_timestamp($img); |
|
| 986 | + if (!file_exists($img)) { |
|
| 987 | + return false; |
|
| 988 | + } |
|
| 989 | + @copy($img, $tmp); |
|
| 990 | + if (filesize($tmp) == filesize($img)) { |
|
| 991 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 992 | + @rename($tmp, $fichier); |
|
| 993 | + return true; |
|
| 994 | + } |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + file_put_contents($tmp, $img); |
|
| 999 | + if (file_exists($tmp)) { |
|
| 1000 | + $taille_test = spip_getimagesize($tmp); |
|
| 1001 | + if (empty($taille_test[0])) { |
|
| 1002 | + return false; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1006 | + @rename($tmp, $fichier); |
|
| 1007 | + |
|
| 1008 | + return true; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + return false; |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | |
@@ -1036,30 +1036,30 @@ discard block |
||
| 1036 | 1036 | * - false sinon. |
| 1037 | 1037 | */ |
| 1038 | 1038 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1039 | - if (is_null($fonction)) { |
|
| 1040 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1041 | - } |
|
| 1042 | - $ret = false; |
|
| 1043 | - #un flag pour reperer les images gravees |
|
| 1044 | - $lock = ( |
|
| 1045 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1046 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1047 | - ); |
|
| 1048 | - if ( |
|
| 1049 | - function_exists($fonction) |
|
| 1050 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1051 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1052 | - && !$lock |
|
| 1053 | - ) { |
|
| 1054 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1055 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1056 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1057 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1058 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1059 | - } |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - return $ret; |
|
| 1039 | + if (is_null($fonction)) { |
|
| 1040 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1041 | + } |
|
| 1042 | + $ret = false; |
|
| 1043 | + #un flag pour reperer les images gravees |
|
| 1044 | + $lock = ( |
|
| 1045 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1046 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1047 | + ); |
|
| 1048 | + if ( |
|
| 1049 | + function_exists($fonction) |
|
| 1050 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1051 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1052 | + && !$lock |
|
| 1053 | + ) { |
|
| 1054 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1055 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1056 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1057 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1058 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1059 | + } |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + return $ret; |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | /** |
@@ -1072,27 +1072,27 @@ discard block |
||
| 1072 | 1072 | * Chemin vers le fichier manquant |
| 1073 | 1073 | **/ |
| 1074 | 1074 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1075 | - $reconstruire = []; |
|
| 1076 | - $fichier = $fichier_manquant; |
|
| 1077 | - while ( |
|
| 1078 | - strpos($fichier, '://') === false |
|
| 1079 | - and !@file_exists($fichier) |
|
| 1080 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1081 | - and $valeurs = unserialize($source) |
|
| 1082 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1083 | - ) { |
|
| 1084 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1085 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1086 | - } |
|
| 1087 | - while (count($reconstruire)) { |
|
| 1088 | - $r = array_pop($reconstruire); |
|
| 1089 | - $fonction = $r[0]; |
|
| 1090 | - $args = $r[1]; |
|
| 1091 | - $fonction(...$args); |
|
| 1092 | - } |
|
| 1093 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1094 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1095 | - ramasse_miettes($fichier_manquant); |
|
| 1075 | + $reconstruire = []; |
|
| 1076 | + $fichier = $fichier_manquant; |
|
| 1077 | + while ( |
|
| 1078 | + strpos($fichier, '://') === false |
|
| 1079 | + and !@file_exists($fichier) |
|
| 1080 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1081 | + and $valeurs = unserialize($source) |
|
| 1082 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1083 | + ) { |
|
| 1084 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1085 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1086 | + } |
|
| 1087 | + while (count($reconstruire)) { |
|
| 1088 | + $r = array_pop($reconstruire); |
|
| 1089 | + $fonction = $r[0]; |
|
| 1090 | + $args = $r[1]; |
|
| 1091 | + $fonction(...$args); |
|
| 1092 | + } |
|
| 1093 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1094 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1095 | + ramasse_miettes($fichier_manquant); |
|
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | /** |
@@ -1112,28 +1112,28 @@ discard block |
||
| 1112 | 1112 | * Chemin du fichier d'image calculé |
| 1113 | 1113 | **/ |
| 1114 | 1114 | function ramasse_miettes($fichier) { |
| 1115 | - if ( |
|
| 1116 | - strpos($fichier, '://') !== false |
|
| 1117 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1118 | - or !$valeurs = unserialize($source) |
|
| 1119 | - ) { |
|
| 1120 | - return; |
|
| 1121 | - } |
|
| 1122 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1123 | - while ( |
|
| 1124 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1125 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1126 | - and (lire_fichier( |
|
| 1127 | - $src = "$fichier.src", |
|
| 1128 | - $source |
|
| 1129 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1130 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1131 | - ) { |
|
| 1132 | - # on efface le fichier |
|
| 1133 | - spip_unlink($fichier); |
|
| 1134 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1135 | - #spip_unlink($src); |
|
| 1136 | - } |
|
| 1115 | + if ( |
|
| 1116 | + strpos($fichier, '://') !== false |
|
| 1117 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1118 | + or !$valeurs = unserialize($source) |
|
| 1119 | + ) { |
|
| 1120 | + return; |
|
| 1121 | + } |
|
| 1122 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1123 | + while ( |
|
| 1124 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1125 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1126 | + and (lire_fichier( |
|
| 1127 | + $src = "$fichier.src", |
|
| 1128 | + $source |
|
| 1129 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1130 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1131 | + ) { |
|
| 1132 | + # on efface le fichier |
|
| 1133 | + spip_unlink($fichier); |
|
| 1134 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1135 | + #spip_unlink($src); |
|
| 1136 | + } |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
@@ -1158,31 +1158,31 @@ discard block |
||
| 1158 | 1158 | * Code HTML de l'image |
| 1159 | 1159 | **/ |
| 1160 | 1160 | function image_graver($img) { |
| 1161 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1162 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1163 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1164 | - |
|
| 1165 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1166 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1167 | - $fichier = substr($fichier, 0, $p); |
|
| 1168 | - } |
|
| 1169 | - if (strlen($fichier) < 1) { |
|
| 1170 | - $fichier = $img; |
|
| 1171 | - } |
|
| 1172 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1173 | - # et qu'il ne s'agit pas d'une URL |
|
| 1174 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1175 | - reconstruire_image_intermediaire($fichier); |
|
| 1176 | - } |
|
| 1177 | - ramasse_miettes($fichier); |
|
| 1178 | - |
|
| 1179 | - // ajouter le timestamp si besoin |
|
| 1180 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1181 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1182 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - return $img; |
|
| 1161 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1162 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1163 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1164 | + |
|
| 1165 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1166 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1167 | + $fichier = substr($fichier, 0, $p); |
|
| 1168 | + } |
|
| 1169 | + if (strlen($fichier) < 1) { |
|
| 1170 | + $fichier = $img; |
|
| 1171 | + } |
|
| 1172 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1173 | + # et qu'il ne s'agit pas d'une URL |
|
| 1174 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1175 | + reconstruire_image_intermediaire($fichier); |
|
| 1176 | + } |
|
| 1177 | + ramasse_miettes($fichier); |
|
| 1178 | + |
|
| 1179 | + // ajouter le timestamp si besoin |
|
| 1180 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1181 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1182 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + return $img; |
|
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | /** |
@@ -1209,34 +1209,34 @@ discard block |
||
| 1209 | 1209 | * Code html modifié de la balise. |
| 1210 | 1210 | **/ |
| 1211 | 1211 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1212 | - if ($style === false) { |
|
| 1213 | - $style = extraire_attribut($tag, 'style'); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // enlever le width et height du style |
|
| 1217 | - if ($style) { |
|
| 1218 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1219 | - } |
|
| 1220 | - if ($style and $style[0] === ';') { |
|
| 1221 | - $style = substr($style, 1); |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - // mettre des attributs de width et height sur les images, |
|
| 1225 | - // ca accelere le rendu du navigateur |
|
| 1226 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1227 | - // quand on a desactive l'affichage des images. |
|
| 1228 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1229 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1230 | - |
|
| 1231 | - // attributs deprecies. Transformer en CSS |
|
| 1232 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1233 | - $style = "margin:{$espace}px;" . $style; |
|
| 1234 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1238 | - |
|
| 1239 | - return $tag; |
|
| 1212 | + if ($style === false) { |
|
| 1213 | + $style = extraire_attribut($tag, 'style'); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // enlever le width et height du style |
|
| 1217 | + if ($style) { |
|
| 1218 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1219 | + } |
|
| 1220 | + if ($style and $style[0] === ';') { |
|
| 1221 | + $style = substr($style, 1); |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + // mettre des attributs de width et height sur les images, |
|
| 1225 | + // ca accelere le rendu du navigateur |
|
| 1226 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1227 | + // quand on a desactive l'affichage des images. |
|
| 1228 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1229 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1230 | + |
|
| 1231 | + // attributs deprecies. Transformer en CSS |
|
| 1232 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1233 | + $style = "margin:{$espace}px;" . $style; |
|
| 1234 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1238 | + |
|
| 1239 | + return $tag; |
|
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | |
@@ -1262,72 +1262,72 @@ discard block |
||
| 1262 | 1262 | * Retourne le code HTML de l'image |
| 1263 | 1263 | **/ |
| 1264 | 1264 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1265 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1266 | - |
|
| 1267 | - // fermer les tags img pas bien fermes; |
|
| 1268 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1269 | - |
|
| 1270 | - // le style |
|
| 1271 | - $style = $valeurs['style']; |
|
| 1272 | - if (isset($surcharge['style'])) { |
|
| 1273 | - $style = $surcharge['style']; |
|
| 1274 | - unset($surcharge['style']); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - // traiter specifiquement la largeur et la hauteur |
|
| 1278 | - $width = $valeurs['largeur']; |
|
| 1279 | - if (isset($surcharge['width'])) { |
|
| 1280 | - $width = $surcharge['width']; |
|
| 1281 | - unset($surcharge['width']); |
|
| 1282 | - } |
|
| 1283 | - $height = $valeurs['hauteur']; |
|
| 1284 | - if (isset($surcharge['height'])) { |
|
| 1285 | - $height = $surcharge['height']; |
|
| 1286 | - unset($surcharge['height']); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1290 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1291 | - // on remplace toute les ref a src dans le tag |
|
| 1292 | - $src = extraire_attribut($tag, 'src'); |
|
| 1293 | - if (isset($surcharge['src'])) { |
|
| 1294 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1295 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1296 | - // pas garanti comme methode, mais mieux que rien |
|
| 1297 | - if (strpos($src, '&') !== false) { |
|
| 1298 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1299 | - } |
|
| 1300 | - $src = $surcharge['src']; |
|
| 1301 | - unset($surcharge['src']); |
|
| 1302 | - } |
|
| 1303 | - |
|
| 1304 | - $class = $valeurs['class']; |
|
| 1305 | - if (isset($surcharge['class'])) { |
|
| 1306 | - $class = $surcharge['class']; |
|
| 1307 | - unset($surcharge['class']); |
|
| 1308 | - } |
|
| 1309 | - if (is_scalar($class) && strlen($class)) { |
|
| 1310 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - if (count($surcharge)) { |
|
| 1314 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1315 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - |
|
| 1319 | - $tag = pipeline( |
|
| 1320 | - 'image_ecrire_tag_finir', |
|
| 1321 | - [ |
|
| 1322 | - 'args' => [ |
|
| 1323 | - 'valeurs' => $valeurs, |
|
| 1324 | - 'surcharge' => $surcharge, |
|
| 1325 | - ], |
|
| 1326 | - 'data' => $tag |
|
| 1327 | - ] |
|
| 1328 | - ); |
|
| 1329 | - |
|
| 1330 | - return $tag; |
|
| 1265 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1266 | + |
|
| 1267 | + // fermer les tags img pas bien fermes; |
|
| 1268 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1269 | + |
|
| 1270 | + // le style |
|
| 1271 | + $style = $valeurs['style']; |
|
| 1272 | + if (isset($surcharge['style'])) { |
|
| 1273 | + $style = $surcharge['style']; |
|
| 1274 | + unset($surcharge['style']); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + // traiter specifiquement la largeur et la hauteur |
|
| 1278 | + $width = $valeurs['largeur']; |
|
| 1279 | + if (isset($surcharge['width'])) { |
|
| 1280 | + $width = $surcharge['width']; |
|
| 1281 | + unset($surcharge['width']); |
|
| 1282 | + } |
|
| 1283 | + $height = $valeurs['hauteur']; |
|
| 1284 | + if (isset($surcharge['height'])) { |
|
| 1285 | + $height = $surcharge['height']; |
|
| 1286 | + unset($surcharge['height']); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1290 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1291 | + // on remplace toute les ref a src dans le tag |
|
| 1292 | + $src = extraire_attribut($tag, 'src'); |
|
| 1293 | + if (isset($surcharge['src'])) { |
|
| 1294 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1295 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1296 | + // pas garanti comme methode, mais mieux que rien |
|
| 1297 | + if (strpos($src, '&') !== false) { |
|
| 1298 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1299 | + } |
|
| 1300 | + $src = $surcharge['src']; |
|
| 1301 | + unset($surcharge['src']); |
|
| 1302 | + } |
|
| 1303 | + |
|
| 1304 | + $class = $valeurs['class']; |
|
| 1305 | + if (isset($surcharge['class'])) { |
|
| 1306 | + $class = $surcharge['class']; |
|
| 1307 | + unset($surcharge['class']); |
|
| 1308 | + } |
|
| 1309 | + if (is_scalar($class) && strlen($class)) { |
|
| 1310 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + if (count($surcharge)) { |
|
| 1314 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1315 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + |
|
| 1319 | + $tag = pipeline( |
|
| 1320 | + 'image_ecrire_tag_finir', |
|
| 1321 | + [ |
|
| 1322 | + 'args' => [ |
|
| 1323 | + 'valeurs' => $valeurs, |
|
| 1324 | + 'surcharge' => $surcharge, |
|
| 1325 | + ], |
|
| 1326 | + 'data' => $tag |
|
| 1327 | + ] |
|
| 1328 | + ); |
|
| 1329 | + |
|
| 1330 | + return $tag; |
|
| 1331 | 1331 | } |
| 1332 | 1332 | |
| 1333 | 1333 | /** |
@@ -1350,268 +1350,268 @@ discard block |
||
| 1350 | 1350 | * Description de l'image, sinon null. |
| 1351 | 1351 | **/ |
| 1352 | 1352 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1353 | - $srcHeight = null; |
|
| 1354 | - $retour = []; |
|
| 1355 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1356 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1357 | - $image = $valeurs['fichier']; |
|
| 1358 | - $format = $valeurs['format_source']; |
|
| 1359 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1360 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1361 | - |
|
| 1362 | - $format_sortie = $valeurs['format_dest']; |
|
| 1363 | - |
|
| 1364 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1365 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1369 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1370 | - return; |
|
| 1371 | - } |
|
| 1372 | - $destination = "$destdir/$destfile"; |
|
| 1373 | - |
|
| 1374 | - // calculer la taille |
|
| 1375 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1376 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1377 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1378 | - } |
|
| 1379 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1380 | - $destWidth = $maxWidth; |
|
| 1381 | - $destHeight = $maxHeight; |
|
| 1382 | - } else { |
|
| 1383 | - spip_log("echec $process sur $image"); |
|
| 1384 | - |
|
| 1385 | - return; |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - $vignette = ''; |
|
| 1389 | - |
|
| 1390 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1391 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1392 | - $vignette = $destination . '.' . $format; |
|
| 1393 | - @copy($image, $vignette); |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1397 | - include_spip('inc/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 . ' -orient Undefined -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; |
|
| 1353 | + $srcHeight = null; |
|
| 1354 | + $retour = []; |
|
| 1355 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1356 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1357 | + $image = $valeurs['fichier']; |
|
| 1358 | + $format = $valeurs['format_source']; |
|
| 1359 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1360 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1361 | + |
|
| 1362 | + $format_sortie = $valeurs['format_dest']; |
|
| 1363 | + |
|
| 1364 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1365 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1369 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1370 | + return; |
|
| 1371 | + } |
|
| 1372 | + $destination = "$destdir/$destfile"; |
|
| 1373 | + |
|
| 1374 | + // calculer la taille |
|
| 1375 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1376 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1377 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1378 | + } |
|
| 1379 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1380 | + $destWidth = $maxWidth; |
|
| 1381 | + $destHeight = $maxHeight; |
|
| 1382 | + } else { |
|
| 1383 | + spip_log("echec $process sur $image"); |
|
| 1384 | + |
|
| 1385 | + return; |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + $vignette = ''; |
|
| 1389 | + |
|
| 1390 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1391 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1392 | + $vignette = $destination . '.' . $format; |
|
| 1393 | + @copy($image, $vignette); |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1397 | + include_spip('inc/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 . ' -orient Undefined -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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $blue = dechex($blue); |
| 43 | 43 | |
| 44 | 44 | if (strlen($red) == 1) { |
| 45 | - $red = '0' . $red; |
|
| 45 | + $red = '0'.$red; |
|
| 46 | 46 | } |
| 47 | 47 | if (strlen($green) == 1) { |
| 48 | - $green = '0' . $green; |
|
| 48 | + $green = '0'.$green; |
|
| 49 | 49 | } |
| 50 | 50 | if (strlen($blue) == 1) { |
| 51 | - $blue = '0' . $blue; |
|
| 51 | + $blue = '0'.$blue; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return "$red$green$blue"; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $couleur = couleur_html_to_hex($couleur); |
| 68 | 68 | $couleur = ltrim($couleur, '#'); |
| 69 | 69 | if (strlen($couleur) === 3) { |
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 70 | + $couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2]; |
|
| 71 | 71 | } |
| 72 | 72 | $retour = []; |
| 73 | 73 | $retour['red'] = hexdec(substr($couleur, 0, 2)); |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | $var_G = ($G / 255); |
| 126 | 126 | $var_B = ($B / 255); |
| 127 | 127 | |
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | 131 | |
| 132 | 132 | $L = ($var_Max + $var_Min) / 2; |
| 133 | 133 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | 191 | // helper |
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | + $hue_2_rgb = function($v1, $v2, $vH) { |
|
| 193 | 193 | if ($vH < 0) { |
| 194 | 194 | $vH += 1; |
| 195 | 195 | } |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | $img = "<img src='$source' />"; |
| 322 | 322 | } elseif ( |
| 323 | 323 | preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]) |
|
| 325 | 325 | and in_array($extension, _image_extensions_acceptees_en_entree()) |
| 326 | 326 | ) { |
| 327 | 327 | # gerer img src="data:....base64" |
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension); |
|
| 329 | 329 | if (!file_exists($local)) { |
| 330 | 330 | ecrire_fichier($local, base64_decode($regs[2])); |
| 331 | 331 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // les protocoles web prennent au moins 3 lettres |
| 343 | 343 | if (tester_url_absolue($source)) { |
| 344 | 344 | include_spip('inc/distant'); |
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 346 | 346 | if (!$fichier) { |
| 347 | 347 | return ''; |
| 348 | 348 | } |
@@ -444,9 +444,9 @@ discard block |
||
| 444 | 444 | // on garde la terminaison initiale car image simplement copiee |
| 445 | 445 | // et on postfixe son nom avec un md5 du path |
| 446 | 446 | $terminaison_dest = $terminaison; |
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 447 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 448 | 448 | } else { |
| 449 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 449 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 450 | 450 | } |
| 451 | 451 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 452 | 452 | $cache = sous_repertoire($cache, $effet); |
@@ -457,7 +457,7 @@ discard block |
||
| 457 | 457 | $fichier_dest = substr($fichier_dest, 2); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 460 | + $fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest; |
|
| 461 | 461 | |
| 462 | 462 | $GLOBALS['images_calculees'][] = $fichier_dest; |
| 463 | 463 | |
@@ -495,15 +495,15 @@ discard block |
||
| 495 | 495 | |
| 496 | 496 | if ($creer) { |
| 497 | 497 | spip_log( |
| 498 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 499 | - 'images' . _LOG_DEBUG |
|
| 498 | + 'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 499 | + 'images'._LOG_DEBUG |
|
| 500 | 500 | ); |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | $term_fonction = _image_trouver_extension_pertinente($fichier); |
| 504 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 504 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction; |
|
| 505 | 505 | $ret['fichier'] = $fichier; |
| 506 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 506 | + $ret['fonction_image'] = '_image_image'.$terminaison_dest; |
|
| 507 | 507 | $ret['fichier_dest'] = $fichier_dest; |
| 508 | 508 | $ret['format_source'] = _image_extension_normalisee($terminaison); |
| 509 | 509 | $ret['format_dest'] = $terminaison_dest; |
@@ -653,7 +653,7 @@ discard block |
||
| 653 | 653 | |
| 654 | 654 | $_terminaison = _image_trouver_extension_depuis_mime($mime); |
| 655 | 655 | if ($_terminaison and $_terminaison !== $terminaison) { |
| 656 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 656 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE); |
|
| 657 | 657 | $terminaison = $_terminaison; |
| 658 | 658 | } |
| 659 | 659 | return $terminaison; |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | if (!function_exists('imagepng')) { |
| 811 | 811 | return false; |
| 812 | 812 | } |
| 813 | - $tmp = $fichier . '.tmp'; |
|
| 813 | + $tmp = $fichier.'.tmp'; |
|
| 814 | 814 | $ret = imagepng($img, $tmp); |
| 815 | 815 | if (file_exists($tmp)) { |
| 816 | 816 | $taille_test = @getimagesize($tmp); |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | if (!function_exists('imagegif')) { |
| 846 | 846 | return false; |
| 847 | 847 | } |
| 848 | - $tmp = $fichier . '.tmp'; |
|
| 848 | + $tmp = $fichier.'.tmp'; |
|
| 849 | 849 | $ret = imagegif($img, $tmp); |
| 850 | 850 | if (file_exists($tmp)) { |
| 851 | 851 | $taille_test = @getimagesize($tmp); |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | if (!function_exists('imagejpeg')) { |
| 886 | 886 | return false; |
| 887 | 887 | } |
| 888 | - $tmp = $fichier . '.tmp'; |
|
| 888 | + $tmp = $fichier.'.tmp'; |
|
| 889 | 889 | |
| 890 | 890 | // Enable interlancing |
| 891 | 891 | imageinterlace($img, true); |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | if (!function_exists('imagewebp')) { |
| 947 | 947 | return false; |
| 948 | 948 | } |
| 949 | - $tmp = $fichier . '.tmp'; |
|
| 949 | + $tmp = $fichier.'.tmp'; |
|
| 950 | 950 | $ret = imagewebp($img, $tmp, $qualite); |
| 951 | 951 | if (file_exists($tmp)) { |
| 952 | 952 | $taille_test = @getimagesize($tmp); |
@@ -980,7 +980,7 @@ discard block |
||
| 980 | 980 | */ |
| 981 | 981 | function _image_imagesvg($img, $fichier) { |
| 982 | 982 | |
| 983 | - $tmp = $fichier . '.tmp'; |
|
| 983 | + $tmp = $fichier.'.tmp'; |
|
| 984 | 984 | if (strpos($img, '<') === false) { |
| 985 | 985 | $img = supprimer_timestamp($img); |
| 986 | 986 | if (!file_exists($img)) { |
@@ -1037,13 +1037,13 @@ discard block |
||
| 1037 | 1037 | */ |
| 1038 | 1038 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1039 | 1039 | if (is_null($fonction)) { |
| 1040 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1040 | + $fonction = '_image_image'.$valeurs['format_dest']; |
|
| 1041 | 1041 | } |
| 1042 | 1042 | $ret = false; |
| 1043 | 1043 | #un flag pour reperer les images gravees |
| 1044 | 1044 | $lock = ( |
| 1045 | 1045 | !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
| 1046 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1046 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src')) |
|
| 1047 | 1047 | ); |
| 1048 | 1048 | if ( |
| 1049 | 1049 | function_exists($fonction) |
@@ -1055,7 +1055,7 @@ discard block |
||
| 1055 | 1055 | // dans tous les cas mettre a jour la taille de l'image finale |
| 1056 | 1056 | [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
| 1057 | 1057 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
| 1058 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1058 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 1059 | 1059 | } |
| 1060 | 1060 | } |
| 1061 | 1061 | |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | |
| 1231 | 1231 | // attributs deprecies. Transformer en CSS |
| 1232 | 1232 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 1233 | - $style = "margin:{$espace}px;" . $style; |
|
| 1233 | + $style = "margin:{$espace}px;".$style; |
|
| 1234 | 1234 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 1235 | 1235 | } |
| 1236 | 1236 | |
@@ -1357,7 +1357,7 @@ discard block |
||
| 1357 | 1357 | $image = $valeurs['fichier']; |
| 1358 | 1358 | $format = $valeurs['format_source']; |
| 1359 | 1359 | $destdir = dirname($valeurs['fichier_dest']); |
| 1360 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1360 | + $destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']); |
|
| 1361 | 1361 | |
| 1362 | 1362 | $format_sortie = $valeurs['format_dest']; |
| 1363 | 1363 | |
@@ -1389,7 +1389,7 @@ discard block |
||
| 1389 | 1389 | |
| 1390 | 1390 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 1391 | 1391 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1392 | - $vignette = $destination . '.' . $format; |
|
| 1392 | + $vignette = $destination.'.'.$format; |
|
| 1393 | 1393 | @copy($image, $vignette); |
| 1394 | 1394 | } |
| 1395 | 1395 | |
@@ -1397,7 +1397,7 @@ discard block |
||
| 1397 | 1397 | include_spip('inc/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 |
||
| 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 . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1412 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -orient Undefined -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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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]); |